He is a real competitive programmer in all KZbinrs who teaches DSA in India
@lakshsinghania6 ай бұрын
guys who do cp have better problem solving skills, even doing dsa gives but cp just opens the brain to think in diff solutions
@harshgupta52874 ай бұрын
Just a small change in the code for those who are wondering why 191th test case is not passing on leetcode, just change the data type of ans, pre and suff to double so as to prevent overflow in the intermediate steps. It has much bigger range than long and long long. Btw great explaination striver!!
@brp35223 ай бұрын
Saved me hours of wondering. Thanks mate appreciate it
@codersoham3 ай бұрын
Thanks a lot bro. I was searching for this for hours until I saw your comment.
@deepk-0073 ай бұрын
Bro is the saviour.
@secondthread-uc9bd3 ай бұрын
works but cheating lol
@brp35223 ай бұрын
@@secondthread-uc9bd How's this cheating dude??
@SHASHANKRUSTAGII Жыл бұрын
I had never seen this approach and the way you explain is like you own it.!!! Superb work striver bro
@takeUforward Жыл бұрын
;)
@chiragbansod82528 ай бұрын
Completed this playlist also, MAN this is the best teacher of DSA. UNDERSTOOD!!!!!!!
@sasanklakimsetti8967Ай бұрын
Great explanantion. Without using dynamic programming and not encountering any overlapping subproblem, he solved it and of course, explained like a boss. And he is. What a man!🙌🙌
@pramodharshav6091 Жыл бұрын
You're God sent for us to learn in last moment ❤
@AbjSir Жыл бұрын
Arrays completed Tomorrow I will revise full arrays before starting binary search
@gpraneeth76933 ай бұрын
How
@SusinSunilkumar11 ай бұрын
bro no need any more examples you were the best in explaining this question with the most examples the cases... Really understood the concept very well. Thank you for the video...
@MischievousSoul Жыл бұрын
I was literally searching for the intuitive approach and finally found it.. really appreciate it.. and a great explanation..
@shreyasingh98472 күн бұрын
I am so happy I found your channel because every time when I searched for a solution I would directly get optimized code and I be like how they thought of this, from where did that come in their mind but you build solution making it better and better and it makes things so much better like I can recognize patterns. Thank you so much for your guidance.
@aryanyadav3926 Жыл бұрын
Brilliant! this is actually much more intuitive as I was also thinking of applying prefix and suffix in it, just couldn't react to the final answer. Thanks.
@messi_codes Жыл бұрын
Best Solution , will never forget this solution .
@vikasbagri1225 Жыл бұрын
I do not know who has observed the optimal approach but whoever the guy was, it was brilliant Thanks for your explanation Striver Understood it very well And waiting for your Binary Search series...
@belugaop77847 ай бұрын
i generally dont comment on videos , but yaar striver truly is a genius
@calvinseptyanto311010 ай бұрын
Had to give this a like, can't lie the best explanation for this problem.
@moviesbuddy42283 ай бұрын
class Solution { public: int maxProduct(vector& nums) { double prefix = 1, suffix = 1 , ans = INT_MIN; int n = nums.size(); for(int i=0;i
@shubhamagarwal14343 ай бұрын
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.....
@CrytpoDeFi308 Жыл бұрын
Was struggling to understand the explanation of this problem, but after tour video I am amazed how easy it is :D
@najimali326 ай бұрын
This approach is awesome! I've seen others teaching the same old Kadane approach, but this observation-based method is a real gem. Keep up the great work and keep sharing your insights!
@AJK-a2j00k47 ай бұрын
The way he did it in one go without taking separate arrays before and after 0 like I did.. hatsoff you are truly amazing!
@KarthikNandam-xs4qnАй бұрын
THE GOAT of the DSA prep 🔥 hands down 🙌
@CinematicClips-uz3mk6 ай бұрын
Completed this playlist.... Gain confidence and knowledge.... Thank you Bhaiya ❤❤
@Manishgupta200 Жыл бұрын
The logical thinking It's very easy to understand.. with TC -> O(N) and SC -> O(1)
@Anything-cx4bs5 ай бұрын
you are really the best teacher available on youtube
@madhulikaghosh38768 ай бұрын
Happy to see your video. So many videos I watched for this question. Finally i can get the intutive for the question.
@councilaxe Жыл бұрын
The ans=max() part should come before we set the prefix and suffix as 1 Otherwise say in cases like [-ve ,0,-ve] the answer will be 1 instead of 0
@Shanky_17 Жыл бұрын
Nice obs..
@adityagoswami6881 Жыл бұрын
the solution was giving error for leetcode test case, so i put the finding max part before if condition , the solution got accepted
@Ali-kf6jk Жыл бұрын
It should work if at the start you intitialize the max at min_int or min infinity in python. This way 0 will get picked. No need to change the max() part.
@shivanshuranjan-iitbhu889 Жыл бұрын
Another thing you can do is to store the maximum element of array in a maxele variable and return max(maxele,ans)
@anshusoni62615 ай бұрын
But the solution is giving runtime error on Leetcode
@saunaknandi1814 Жыл бұрын
Hey Striver can you add the famous Egg Dropping Problem in your DP series? It will be of great help to many students.
@KishoreKumar-xr3fu6 ай бұрын
Best explanation ever i have seen for this. Thank you bro 🙏
@tungvuthanh5537 Жыл бұрын
I have watched the solution of neetcode and i must admit that you solution is very intuitive 😂
@Brutal-gz3jz5 ай бұрын
In leetcode take double for suffix,prefix and return value .so the last test case not gonna be int overflow
@sumeetsinghaaryan4 ай бұрын
double maxPro = Integer.MIN_VALUE; double pre = 1, suff = 1; int len = nums.length; for(int i=0; i
@shishirkarki90014 ай бұрын
@@sumeetsinghaaryan why is it working for double but shows overflow error when using long?
@VISHALTHAKUR-gg3dg4 ай бұрын
@@shishirkarki9001 i also didnt get it ?
@shishirkarki90014 ай бұрын
@@VISHALTHAKUR-gg3dg i came to know that double has larger range than long
@sumanpradhan41054 ай бұрын
thanks broooo
@torishi824 ай бұрын
Best explanations and best qualities. You are a striver indeed.
@shivanitayde91773 ай бұрын
bro, you are awesome, no one teaching the DSA like you teach us ..keep going, bro
@Rohit-fz4vd7 ай бұрын
im so happy that i did this prblm both brute and optimal by myself....only difference in my code was i did traversal two times to calc prefix and suffix😅. BTW THANKS STRIVER YOU ARE GREAT🙇
@iamprateek32207 ай бұрын
if you're getting error due to testcases with starting or ending zeroes, then this solution should work: #include #include using namespace std; int subarrayWithMaxProduct(vector &arr){ int n=arr.size(); int pre=1, suff=1,maxprod=INT_MIN,prezero=0,suffzero=0; for(int i=0;i
@christinajoice3838Ай бұрын
A big shout out to you, well explained, I had the observation to some extent (to the even negative handlings), but i couldnt go till coding my observation completely, this is really well explained. Thanks Striver :)
@cinime Жыл бұрын
Understood! Super awesome explanation as always, thank you very very very much for your effort!!
@santanu29 Жыл бұрын
You learn something new everyday ❤. This is the reason I love your videos. Got to learn something new.
@shambhaviaggarwal9977Ай бұрын
This was such a beautiful and elegant approach
@AbhishekKumar-dl6ko6 ай бұрын
Completed Arrays on 09/05/24 ..Superb Content and Explanation .....
@stith_pragya7 ай бұрын
UNDERSTOOD.............Thanks a ton............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@stith_pragya7 ай бұрын
Thank You So Much for this wonderful video.......................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@halcyonramirez6469 Жыл бұрын
I actually understand this and it makes so much sense. Thanks!
@trailblazer5555 ай бұрын
The way he explained made me to think how to really approach a problem with logical thinking...Great Striver!!!
@GOJOANDSUKUNAFAN5 ай бұрын
How can you help me please
@dhanushsanapala32874 ай бұрын
the best approach i have ever seen
@ChiragNanda-k6j10 ай бұрын
Thanks for the great playlists for DSA
@thedon713 Жыл бұрын
Hey Brother..At first thank you for your great work..Now I am learning Recursion from your recursion playlist..Love you from Bangladesh
@sudiptamaity-e Жыл бұрын
I solved this problem using a extended version of kadane's algorithm: class Solution { public int maxProduct(int[] nums) { int currmin=1,currmax=1,max=nums[0]; for(int n:nums) { int temp=currmax*n; currmax=Math.max(currmax*n,Math.max(currmin*n,n)); currmin=Math.min(temp,Math.min(currmin*n,n)); max=Math.max(max,currmax); } return max; } }
@akshdhingra27005 ай бұрын
This Guy is Next Level
@ashutoshupadhyay5683 Жыл бұрын
u just fired it man.....what an awesome explanation....Thanks bro for the help.
@killeraloo3247 Жыл бұрын
Bhai mast video thi. Teeno algo's samajh mein aa gyin.
@anshlyk Жыл бұрын
Thanks for the great explanation, it feels like you are explaining me one to one the way you place your face on the screen!!
@dank70444 ай бұрын
I think the super clean implementation was very nice.
@playwithlinux5 ай бұрын
Nice Explanation and intuition for this problem.. Thanks a million Striver. ♥♥♥
@harshraj3522 Жыл бұрын
finally array completed..thanks striver bhaiya
@CyberZeo2 ай бұрын
Thank you so much for this beautiful explanation
@aryasharma693 ай бұрын
Java code for 191th test case:- class Solution { public int maxProduct(int[] nums) { int n=nums.length; if(n==0)return 0; double ans= Integer.MIN_VALUE; double pref=1, suf=1; for(int i=0; i
@zaid6493 Жыл бұрын
awesome teaching and please teach every problem how to identify the pattern which algo we need to used.. and try to explain all the approaches. by the way your videos are great you will deserve 1m soon.
@selvaarumugam370 Жыл бұрын
U jus explained the problem in a way it was made simple
@hi-tk4hu Жыл бұрын
Yes when I first saw the solution with kadanes it made me depressed fr, but this approach I will never forget
@Irfankhan-nc2gt Жыл бұрын
Thankyou Bro❤ I have Huge of respect and Thankfulness for you 🎉you are doing such a great thing ❤❤
@hrithikmulik84804 ай бұрын
Hey Striver can you add the famous Egg Dropping Problem in your DP series? It will be of great help to many students.
@gauravharbola1334 Жыл бұрын
Hi striver, first of all this is the best video that i have seen till now for this problem. Secondly, don't you think this is kadanes algorithm only. We did the same thing like adding all the elements till the end and when we got a negative element will turned that to 0. But this time we are doing from both the sides....
@prashanthreddy38406 ай бұрын
This approach is excellent.
@sukhpreetsingh5200 Жыл бұрын
amazing explanation just amaze with the approach
@PDSREACTION Жыл бұрын
bro is this array playlist good?
@sukhpreetsingh5200 Жыл бұрын
@@PDSREACTION Not only array but all the playlists brothers without any doubt
@cruzer_blade.9 ай бұрын
best explanation sir 😁😁
@Lord_Biyoma11 ай бұрын
superb and easy to understand explanation !
@ishangujarathi10 Жыл бұрын
the optimal solution, too good and intuitive as you saidd!!!
@hashcodez75711 күн бұрын
Understood again Bhaiya!!
@bajrangijha7 ай бұрын
mind blowing approach
@jaditi9302 ай бұрын
amazing explanation. thanks a lot.
@yogeshedekar607811 ай бұрын
This solution works well except one edge case where we have a 0 in the array and even number of negative elements. In that case there is a possibility that 0 is our final answer if all other multiplications are negative. A simple tweak can help us solve this just maintain a zeroflag and before returning the answer just check if the answer is negative and the zeroFlag is set in that case we will simply return zero as our answer since we have a zero element in the array and the maximum subarray product excluding zero is negative.
@aarzookhunger94874 ай бұрын
But that's already covered. Let's take an example as per your expl. : -4 0 -5 , here 0 exists and even negative elements In the first iteration pref=-4 suff = -5 , max=-5 second : pref=0 , suff=0 , max = 0 third : pref=-5 , suff=-4 , max=0 So we need not take any such flag or maybe you can specify any test case where your approach will work.!
@AnujSingh-us5pwАй бұрын
@aarzookhunger9487 bro first of all -4 is greater than -5, and second consider this case [-3,0,1,-2] here we should get 1 we the code will return 0, so the only we need to do is reset the predix and suffix prod to 1 after the max computation
@sujalchandrakar38745 ай бұрын
This will pass all testcases in leetcode class Solution { public: int maxProduct(vector& nums) { long long pre=1,suf=1; long long maxi=INT_MIN; for(int i=0;i
@kergeysarjakin55925 ай бұрын
thanks bro
@mohammedharoon11674 ай бұрын
Just another level 🔥
@AbhishekGhume5 ай бұрын
One test case fails in leetcode using this solution. Below is the corrected code. Take prefix and suffix as double. class Solution { public int maxProduct(int[] nums) { int max = Integer.MIN_VALUE;; double prefix = 1; double suffix = 1; for(int i=0; i
@bombblaster69454 ай бұрын
can please tell me the for taking it as double
@raghav5354 Жыл бұрын
I am just here to thank you for acknowledging that kadane's algorithm is not intuitive. I thought I was dumb for not being able to come up with kadane's intuition(while every other person I see is like - "oh yes kadane's algorithm, that’s so obvious").
@AdityaSingh-ql9ke Жыл бұрын
After your hinting, I got the approach...but then I realized ,if we have 0s, then what to do
@lokeshroy3944 Жыл бұрын
optimal approach is very intuitive .......but the one pass implementation is not......but u explained it very well
@vineet17285 ай бұрын
Add checks at line 11 and 12, such that prefix and suffix product does not overflow integer limits. if(prefix
@Lakshya-f4l4 ай бұрын
Giving wrong answer at one test case😬
@sahilrao45924 ай бұрын
@@Lakshya-f4l just assign double instead of int .
@graviton0014 ай бұрын
Test case is 3,0,-2,1 its giving wrong answer
@himanshusingh62295 ай бұрын
Huge respect brother♥
@Ramsiya658 Жыл бұрын
Understood striver much love to you
@HarishSubash3 ай бұрын
double prefix = 1; double suffix = 1; pls consider this logic of double to prevent overflow of int data type in the test case of 190
@tanaysingh5348 Жыл бұрын
Really needed this
@ujjvalsharma5055 Жыл бұрын
Great Approach!
@dsa_tutorial5 ай бұрын
really great explaination !!!
@maheshchaugule8940Ай бұрын
Thank you, very helpful
@Josuke2174 ай бұрын
Nice solution
@debanjan10 Жыл бұрын
Areh Dada ,,, watta approach
@LokeshSharma-hm5jz Жыл бұрын
very nice video, Just like a story. Thanks. great
@pubgbattleground9208 Жыл бұрын
ek number solution!!
@rithikgandhi36857 ай бұрын
Great solution
@hashcodez7575 ай бұрын
Understood Bhaiya!!
@saketjaiswalSJ Жыл бұрын
6:58 optimal
@epistemophilicmetalhead945410 ай бұрын
It feels massively illegal to watch these videos for free
@rosepainting8775 Жыл бұрын
I have solved this problem before, but still I would like to know your approach on this
@DeepuPk-g9q2 ай бұрын
Striver, I think you forget one corner case when input array is [-2,0,-1] this the maximum product of subarray is 0 when you run your code the answer if -1 not zero. ie, The product of left side array of 0 is negative and product of right side of arrya of 0 id negative so maximum product is zero. I think you miss this corner case
@anupamsinghmnnitallahabad6226 Жыл бұрын
what an approach sir
@dayashankarlakhotia4943 Жыл бұрын
Good explanation and much intuitive
@BabaHanuman2612 Жыл бұрын
Which topic will u gonna teach next, Binary search or strings?
@ankit_yadav112 ай бұрын
it failed on -2,0,-1 answer is 0 but this gives -1
@niharikakumar153310 ай бұрын
Thank you bhaiya 🙂
@RakeshVishwakarmaVishwakar-c8i Жыл бұрын
Agr apke jaise sir paid me bhi comtemt de toh public pakka legi 🫡🫡