He is a real competitive programmer in all KZbinrs who teaches DSA in India
@lakshsinghania7 ай бұрын
guys who do cp have better problem solving skills, even doing dsa gives but cp just opens the brain to think in diff solutions
@harshgupta52875 ай бұрын
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!!
@brp35224 ай бұрын
Saved me hours of wondering. Thanks mate appreciate it
@codersoham4 ай бұрын
Thanks a lot bro. I was searching for this for hours until I saw your comment.
@deepk-0074 ай бұрын
Bro is the saviour.
@secondthread-uc9bd4 ай бұрын
works but cheating lol
@brp35224 ай бұрын
@@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 Жыл бұрын
;)
@chiragbansod82529 ай бұрын
Completed this playlist also, MAN this is the best teacher of DSA. UNDERSTOOD!!!!!!!
@sasanklakimsetti89672 ай бұрын
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
@gpraneeth76934 ай бұрын
How
@SusinSunilkumar Жыл бұрын
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...
@messi_codes Жыл бұрын
Best Solution , will never forget this solution .
@MischievousSoul Жыл бұрын
I was literally searching for the intuitive approach and finally found it.. really appreciate it.. and a great explanation..
@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.
@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...
@calvinseptyanto311011 ай бұрын
Had to give this a like, can't lie the best explanation for this problem.
@moviesbuddy42284 ай бұрын
class Solution { public: int maxProduct(vector& nums) { double prefix = 1, suffix = 1 , ans = INT_MIN; int n = nums.size(); for(int i=0;i
@shreyasingh9847Ай бұрын
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.
@belugaop77849 ай бұрын
i generally dont comment on videos , but yaar striver truly is a genius
@Brutal-gz3jz6 ай бұрын
In leetcode take double for suffix,prefix and return value .so the last test case not gonna be int overflow
@sumeetsinghaaryan5 ай бұрын
double maxPro = Integer.MIN_VALUE; double pre = 1, suff = 1; int len = nums.length; for(int i=0; i
@shishirkarki90015 ай бұрын
@@sumeetsinghaaryan why is it working for double but shows overflow error when using long?
@VISHALTHAKUR-gg3dg5 ай бұрын
@@shishirkarki9001 i also didnt get it ?
@shishirkarki90015 ай бұрын
@@VISHALTHAKUR-gg3dg i came to know that double has larger range than long
@sumanpradhan41055 ай бұрын
thanks broooo
@stith_pragya8 ай бұрын
UNDERSTOOD.............Thanks a ton............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@amanpreetsinghbawa160015 күн бұрын
🔥Striver fire🔥One of the most mugged up soln turned into an easy observation based soln, Kudos!!!
@madhulikaghosh38769 ай бұрын
Happy to see your video. So many videos I watched for this question. Finally i can get the intutive for the question.
@Anything-cx4bs6 ай бұрын
you are really the best teacher available on youtube
@stith_pragya8 ай бұрын
Thank You So Much for this wonderful video.......................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@CryptoDeFi308 Жыл бұрын
Was struggling to understand the explanation of this problem, but after tour video I am amazed how easy it is :D
@najimali327 ай бұрын
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!
@KishoreKumar-xr3fu7 ай бұрын
Best explanation ever i have seen for this. Thank you bro 🙏
@CinematicClips-uz3mk8 ай бұрын
Completed this playlist.... Gain confidence and knowledge.... Thank you Bhaiya ❤❤
@torishi825 ай бұрын
Best explanations and best qualities. You are a striver indeed.
@shivanitayde91774 ай бұрын
bro, you are awesome, no one teaching the DSA like you teach us ..keep going, bro
@KarthikNandam-xs4qn2 ай бұрын
THE GOAT of the DSA prep 🔥 hands down 🙌
@christinajoice38383 ай бұрын
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 :)
@saunaknandi1814 Жыл бұрын
Hey Striver can you add the famous Egg Dropping Problem in your DP series? It will be of great help to many students.
@sourabhsoni506518 күн бұрын
Well explained. The intuition part is so good.
@tungvuthanh5537 Жыл бұрын
I have watched the solution of neetcode and i must admit that you solution is very intuitive 😂
@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)
@anshusoni62616 ай бұрын
But the solution is giving runtime error on Leetcode
@shambhaviaggarwal99772 ай бұрын
This was such a beautiful and elegant approach
@shubhamagarwal14344 ай бұрын
#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.....
@hegdevishwa16 күн бұрын
Genius!! I did prefix and suffix thing but was caught off guard by 0.
@Rohit-fz4vd8 ай бұрын
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🙇
@halcyonramirez6469 Жыл бұрын
I actually understand this and it makes so much sense. Thanks!
@cinime Жыл бұрын
Understood! Super awesome explanation as always, thank you very very very much for your effort!!
@killeraloo3247 Жыл бұрын
Bhai mast video thi. Teeno algo's samajh mein aa gyin.
@santanu29 Жыл бұрын
You learn something new everyday ❤. This is the reason I love your videos. Got to learn something new.
@Manishgupta200 Жыл бұрын
The logical thinking It's very easy to understand.. with TC -> O(N) and SC -> O(1)
@dhanushsanapala32875 ай бұрын
the best approach i have ever seen
@ChiragNanda-k6j11 ай бұрын
Thanks for the great playlists for DSA
@AbhishekKumar-dl6ko7 ай бұрын
Completed Arrays on 09/05/24 ..Superb Content and Explanation .....
@cruzer_blade.10 ай бұрын
best explanation sir 😁😁
@dank70445 ай бұрын
I think the super clean implementation was very nice.
@playwithlinux6 ай бұрын
Nice Explanation and intuition for this problem.. Thanks a million Striver. ♥♥♥
@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!!
@ashutoshupadhyay5683 Жыл бұрын
u just fired it man.....what an awesome explanation....Thanks bro for the help.
@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
@AJK-a2j00k48 ай бұрын
The way he did it in one go without taking separate arrays before and after 0 like I did.. hatsoff you are truly amazing!
@trailblazer5556 ай бұрын
The way he explained made me to think how to really approach a problem with logical thinking...Great Striver!!!
@GOJOANDSUKUNAFAN6 ай бұрын
How can you help me please
@CyberZeo3 ай бұрын
Thank you so much for this beautiful explanation
@thedon713 Жыл бұрын
Hey Brother..At first thank you for your great work..Now I am learning Recursion from your recursion playlist..Love you from Bangladesh
@iamprateek32208 ай бұрын
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
@akshdhingra27006 ай бұрын
This Guy is Next Level
@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....
@harshraj3522 Жыл бұрын
finally array completed..thanks striver bhaiya
@hashcodez757Ай бұрын
Understood again Bhaiya!!
@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
@Lord_Biyoma Жыл бұрын
superb and easy to understand explanation !
@ishangujarathi10 Жыл бұрын
the optimal solution, too good and intuitive as you saidd!!!
@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.
@mohammedharoon11675 ай бұрын
Just another level 🔥
@hrithikmulik84806 ай бұрын
Hey Striver can you add the famous Egg Dropping Problem in your DP series? It will be of great help to many students.
@jaditi9303 ай бұрын
amazing explanation. thanks a lot.
@himanshusingh62296 ай бұрын
Huge respect brother♥
@Irfankhan-nc2gt Жыл бұрын
Thankyou Bro❤ I have Huge of respect and Thankfulness for you 🎉you are doing such a great thing ❤❤
@Ramsiya658 Жыл бұрын
Understood striver much love to you
@prashanthreddy38407 ай бұрын
This approach is excellent.
@debanjan10 Жыл бұрын
Areh Dada ,,, watta approach
@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; } }
@aryasharma694 ай бұрын
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
@bajrangijha8 ай бұрын
mind blowing approach
@ujjvalsharma5055 Жыл бұрын
Great Approach!
@AbhishekGhume6 ай бұрын
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
@bombblaster69455 ай бұрын
can please tell me the for taking it as double
@tanaysingh5348 Жыл бұрын
Really needed this
@sujalchandrakar38746 ай бұрын
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
@kergeysarjakin55926 ай бұрын
thanks bro
@dsa_tutorial6 ай бұрын
really great explaination !!!
@YourCodeVerse Жыл бұрын
Understood✅🔥🔥
@vineet17286 ай бұрын
Add checks at line 11 and 12, such that prefix and suffix product does not overflow integer limits. if(prefix
@Lakshya-f4l5 ай бұрын
Giving wrong answer at one test case😬
@sahilrao45925 ай бұрын
@@Lakshya-f4l just assign double instead of int .
@graviton0015 ай бұрын
Test case is 3,0,-2,1 its giving wrong answer
@LokeshSharma-hm5jz Жыл бұрын
very nice video, Just like a story. Thanks. great
@AbhishekBhattacharjee-j2m Жыл бұрын
UNDERSTOOD 🔥🔥🔥🔥
@pubgbattleground9208 Жыл бұрын
ek number solution!!
@maheshchaugule89402 ай бұрын
Thank you, very helpful
@hashcodez7576 ай бұрын
Understood Bhaiya!!
@kanha12297 Жыл бұрын
great explanation
@Josuke2175 ай бұрын
Nice solution
@yogeshedekar6078 Жыл бұрын
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.
@aarzookhunger94875 ай бұрын
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-us5pw3 ай бұрын
@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