Maximum Product Subarray | LeetCode 152 | C++, Java, Python

  Рет қаралды 57,760

Knowledge Center

Knowledge Center

3 жыл бұрын

Data Structures & Algorithms course: www.udemy.com/course/data-str...
LeetCode Solutions: • LeetCode Solutions | L...
Github Link: github.com/KnowledgeCenterYou...
*** Best Books For Data Structures & Algorithms for Interviews:*********
1. Cracking the Coding Interview: amzn.to/2WeO3eO
2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
*****************************************************************************
September LeetCoding Challenge | Problem 11 | Maximum Product Subarray | 11 September,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Maximum Product Subarray,
Maximum Product Subarray c++,
Maximum Product Subarray Java,
Maximum Product Subarray python,
Maximum Product Subarray solution,
152. Maximum Product Subarray,
#CodingInterview #LeetCode #Google #Amazon #MaximumProductSum

Пікірлер: 67
@koteshmeesala1630
@koteshmeesala1630 3 жыл бұрын
sir, how do you remember all these algorithms? What is the best way to remember and practice these algorithms? How to get better at these everyday ? I do it everyday, but somehow I feel that I am not following the right approach to solve them
@arpitsatnalika
@arpitsatnalika 3 жыл бұрын
Ever youtuber read geeksforgeeks article before making the video.
@suvamroy6205
@suvamroy6205 3 жыл бұрын
Practise
@kushal3593
@kushal3593 2 жыл бұрын
Crystal clear explanation, 19min well spent. Appreciate the effort
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Thanks. Glad to hear.
@Kidkromechan
@Kidkromechan 2 жыл бұрын
Thank you for the explanation. I wonder who comes up with these ingenious solutions of remembering the minimum numbers to make sure not to lose track of the overall product with negatives along with the max counter lol.
@xinlee3785
@xinlee3785 3 жыл бұрын
Excellent and crisp explanation. Keep up the good work.
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks a lot!
@rahulchudasama9363
@rahulchudasama9363 3 жыл бұрын
In the same problem, how can we find that SubArray?
@danielmcgee2447
@danielmcgee2447 Жыл бұрын
how do you get c++ to allow 3 parameters for max()?
@MayankSingh_is_me
@MayankSingh_is_me 3 жыл бұрын
behad krantikari explanation!!! :D
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Dhanyabaad.
@ujjvalsharma5055
@ujjvalsharma5055 3 жыл бұрын
I must say great video and great explination. It honestly deserves more views I encourage you too make more videos. Your channel will definity grow
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks for the motivating words.
@pillivineeth5103
@pillivineeth5103 3 жыл бұрын
Loved your logic...Thanks
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks and welcome
@anshulcse5733
@anshulcse5733 3 жыл бұрын
Great explanation bro,, keep making such good videos
@feraligatrs
@feraligatrs 3 жыл бұрын
Watched 3 videos before I got to yours and finally understood it! Thank you!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Great to hear!
@jimwoodward7293
@jimwoodward7293 3 жыл бұрын
Here is my solution -- very similar to yours. Thanks! def kadanesMaxProduct(array): maxOverall, minEndingHere, maxEndingHere = 0, 0, 0 for i in array: tmp = maxEndingHere maxEndingHere = max(i, maxEndingHere * i, minEndingHere * i) minEndingHere = min(i, tmp * i, minEndingHere * i) maxOverall = max(maxOverall, maxEndingHere) return maxOverall
@kathaosmart478
@kathaosmart478 3 жыл бұрын
very clear. Thank you
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Glad it was helpful!
@ankushroy919
@ankushroy919 3 жыл бұрын
if our max so far is -10 and min so far is -2 and A[i] is also -ve then this approach will work?
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
maxsofar should not be less than minsofar, if I said that it is a mistake.
@arjunagarwal2248
@arjunagarwal2248 3 жыл бұрын
very detailed explanation!!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks
@paragroy5359
@paragroy5359 3 жыл бұрын
Nice explanation sir...really good video
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks and welcome
@ChristianESL
@ChristianESL 3 жыл бұрын
Can this be considered dynamic programming?
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Yes, in particular this approach would be bottom-up dp, with space optimization.
@venkatarakesh1698
@venkatarakesh1698 3 жыл бұрын
I am python user, can cracking the coding interview book useful to me. Because it has written in java
@xinlee3785
@xinlee3785 3 жыл бұрын
You can understand the logic and write in Python. I also do it. It gives you even more practice.
@akshaysolanki5164
@akshaysolanki5164 3 жыл бұрын
Thanks a lot!!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Pleasure.
@bitrish34
@bitrish34 3 жыл бұрын
Efficient & clear
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks.
@dhanashreegodase4445
@dhanashreegodase4445 2 жыл бұрын
Thanks again
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Welcome
@shreelakshmi6890
@shreelakshmi6890 3 жыл бұрын
nice explanation!
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks! 😃
@tekbssync5727
@tekbssync5727 3 жыл бұрын
your voice is like " Amitabh bacchan " 😂😂
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Haha 😂
@rajatsharma6137
@rajatsharma6137 2 жыл бұрын
dry run was not explained properly.....
@dhananjaygola4786
@dhananjaygola4786 3 жыл бұрын
I wanna know your IDE Did you use this often ? Recommend me the best one plz
@HACKINGMADEFUN
@HACKINGMADEFUN 3 жыл бұрын
VSCode
@elhamabbasi8214
@elhamabbasi8214 3 жыл бұрын
It was a really good explanation, Thanks
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Thanks.
@ayushsingh3553
@ayushsingh3553 3 жыл бұрын
thanks sir
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Welcome.
@AyushKumar-lr9po
@AyushKumar-lr9po 3 жыл бұрын
no use of temp
@Aysh_Sach_16-2
@Aysh_Sach_16-2 3 жыл бұрын
is python not allowed in coding interviews?
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Why not.
@shalomalexander7811
@shalomalexander7811 2 жыл бұрын
I understood how to do it just by watching till 15th min. Nice.
@KnowledgeCenter
@KnowledgeCenter 2 жыл бұрын
Glad to hear.
@shishirpandey7762
@shishirpandey7762 3 жыл бұрын
i don't see zero case being handled here in the code
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
Sometimes I skip base case handling if it's explicitly mentioned in Question. In Question it's mentioned nums.length >= 1.
@yashverma3811
@yashverma3811 3 жыл бұрын
@@KnowledgeCenter i think Shishir was talking about a case when we find 0 in array......if we find 0 then why should we include it because may be our max product is not yet found for example {1,2,0,3,2,1,4} in this case the code you shown will give wrong output. Handle this case please.
@KnowledgeCenter
@KnowledgeCenter 3 жыл бұрын
@@yashverma3811 The code I shown should give 24 as output for your example: {1,2,0,3,2,1,4}. i.e., 3*2*1*4 = 24. please verify, and let me know if it fails.
@yashverma3811
@yashverma3811 3 жыл бұрын
@@KnowledgeCenter yes it is correct sorry i thought it will give wrong output, i understood it now.
@nikostrongioglou9941
@nikostrongioglou9941 3 жыл бұрын
At 08:46 you're saying that "if min_ending was positive then multiply it with the max ending - so whatever was the max_ending and if that is positive multiply it. That will become further positive. So that will be the max". Based on this I am expecting to see something like min_ending=max(min_ending*max_ending, A[i]) in your solution but you end up writing something completely different. Is there any chance you can provide the exhaustive if condition before simplifying it into this 3 liner function?
@master_persi
@master_persi 2 жыл бұрын
max_ending_here=mm, min_ending_here=mn, hope this helps int res=nums[0],mm=nums[0],mn=nums[0],temp=1; for(int i=1;i
@madhavnagpal1860
@madhavnagpal1860 3 жыл бұрын
10 90 91 -91 91 -91 -90 90 90 -90 -90 this test case is failing
@madhavnagpal1860
@madhavnagpal1860 3 жыл бұрын
Its Correct output is: 404928287208900000 And Your Code's output is: 449942298618103232
@Karuska22ps
@Karuska22ps 3 жыл бұрын
how are you even supposed to know how to come up with this bullshit on your own? do people really just memorize the solution?
@snigdhagupta3008
@snigdhagupta3008 3 жыл бұрын
Your explanation is too crooked. You should explain in a structured manner. What is max_ending? and what is min_ending? How did you calculate it??
Maximum Product Subarray - Dynamic Programming - Leetcode 152
15:31
Gas Station | LeetCode 134 | C++, Java, Python
23:02
Knowledge Center
Рет қаралды 31 М.
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 26 МЛН
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 45 МЛН
Maximum Product Subarray - Best Intuitive Approach Discussed
20:27
take U forward
Рет қаралды 181 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 858 М.
why are switch statements so HECKIN fast?
11:03
Low Level Learning
Рет қаралды 394 М.
Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
20:09
take U forward
Рет қаралды 365 М.
Random Point in Non-overlapping Rectangles | LeetCode 497 | C++, Python
26:35
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 633 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 290 М.
What's Your ENGLISH LEVEL? Take This Test!
21:31
Brian Wiles
Рет қаралды 1,7 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 26 МЛН