Today I had my Amazon interview and I got this exact questions and after completing the striver's dp series I was fully able to solve all the approaches and explain it to the interviewer so clearly and he was impressed by the way I explained the approaches and the time and space complexities! THANK YOU STRIVERRR!! You are the bestttt🎈
Hiii ramya, around how long would this playlist take to finish, I have a full time job too : ( Also was your interview for intern position? as this can be simple question for full time role right ?
Understood Sir. At 3:50 min of the video I paused it and went to the recurrence playlist, then watch lecture no 6 & 7 thoroughly and then came here .Amazing session .Thank You Sir for helping us to improve our skills.
Believe me I have been trying to solve dp problems since 6 years and never came across this playlist. Amazing learning technique. This will surely help me in cracking interviews.
Initially I was not able to understand anything related to DSA. I thought that I am not for this. But when i started seeing your videos I found that what I was lacking was a good teacher who is able to understand such advance complex concept in matter of minutes in the best simple way possible. I would have never imagined myself solving hard level dsa questions without you. Thank you sir for all your efforts . Please continue teaching. We will be always with you. THank YoU.
I got confused when you wrote f(ind) at 7:57. Immediately, the pop up rectified the mistake. It's amazing how much work has gone in these videos! I'm loving the playlist till now! Keep up the good work man. Your inputs to the community are huge and they will definitely return back to you in one way or another. Best wishes!
Hats off to this guy whenever we discuss about dp, people just start with tabular method no one teaches how to apprach that, what is the intution behind that approach but this guy making the concepts crystal clear. Thank you so much bhaiya😇
I think we can write one more base case for index = 1. Like 0, when 1 is reached then it means element at 2 wasn't selected and we want to maximize sum so we can select either nums[0] or nums[1] so return max(nums[0], nums[1]) as we need to maximize sum. By doing so we can omit the line that is returning 0 when n < 0 Thanks Striver, Wonderful explanation!
I never had a habit of commenting. But the way you are teaching makes me enthusiatic towards dsa understood each and every concept following from array to dp was a long journey. It wasnt possible without .once again thank u bhai❤
You explained so well, dp was to be hard topic for me but after watching your videos the thought just reversed. Keep going. Most hardworking man i ever seen.
I can find the recurrence relation of a problem and determine whether it is a dynamic programming problem by determining if there is any overlapping sub-problem. The interesting fact is that I have learned these from this playlist. Thanks a lot, bro.
Its good to watch good content for free.. I just finished recursion playlist and now watching DP. For me it is a hard topic, tabulation technique is most difficult but i hope i will get it by the end of this playlist. (NON-CS BACKGROUND)
Understood..You make learning fun :) I am done with my interviews but still don't want to miss learning any concept.This has never been me but all thanks to you :) You're indeed doing a great job!!!
Understood buddy. As usual, great explanation. Get well soon too. Just a request. Need a little more clarity on how to identify whether to approach as a greedy algo or dynamic programming pattern just by looking at a problem.
Generically if u see greedy failing, switch to trying all cases by recursion. For this u need your brain to generate test cases and figure this out that greedy is failing.
As much as I can think if the data is sorted and have uniform difference between them then I think we can go with greedy else dp Correct me if I am wrong plz
@@aakashagarwal146 not uniform but some sort of increasing difference In coin change problem greedy works for 1,2,5,10,20.... becz difference is 1,3,5,10 which is in order and not overlapping but in cases where difference is overlapping or not in any order like when coins are 2,3,6,7. here greedy fails becz the difference is 1,3,1 which is overlapping hope you got the idea
In space optimizations, it's better to initialise things like this: int pre1 = nums[0]; int pre2 = nums[0]; int curr; Just because this makes more sense.
it was literally the best series . i am myself to able to code recursion problems now and its boosting my confidenece and also bhaiya the space optimisation part is just awesome yar
bhaiya you are the best i mean i was confused with dp for so long time and this was becoming the only topic which I was afraid to cover but now my concepts are getting clear and thankyou so much for this series at this time since this will help me do goood in my internships thankyou bhaiya 🥰🤩
This is just the 4th lecture, I struggle a little bit while writing recursive solution, but memoising it, and then tabulating it, and then space optimizing it has become so easier, i never thought dp would be fun. Thank you sir!
Bhaiya Codestudio platform is lagging many a times , could u please provide problem links of similar type that are available on gfg , leetcode , codeforces, codechef etc for practice
hands down the besttt ever video i have ever seen i solved this robber problem using kind of pattern but why i never understood how did it work ...but i always wanted to know how it works internally....but i have to say now that i hate that kind pattern orinted dp problem instead i love this memo and space idea.....Hats off!!!striver bhai❤
No need of if (i > 1), in space optimization. We can directly write like this, as prev2 is 0 anyways. int rob(vector& nums) { int n = nums.size(); int prev = nums[0]; int prev2 = 0; for(int index = 1; index < n; index++) { int rob = nums[index] + prev2; int notRob = 0 + prev; int curr = max(rob, notRob); prev2 = prev; prev = curr; } return prev; }
Understood perfectly, It has been so easy now to convert recursive code to Memoization, Tabulation and then space optimization approach Thanks A Lottt!!!!
Understood!! Thank you for all the efforts in putting up such an amazing playlist! Really sparks my interest in DP, knowing the thought process behind solving every problem. Keep up the good work!
Hii all do not blindly follow, he is a great mentor. There is no doubt but 22:00 he explain tabulation method ,but neg variable is not used,a[index] will be contant at the for loop , output will be definitely wrong. This is the modified code. Pls check it. static int adjSumArray_Tabu(int n,int[] arr,int[] dp) { dp[0] = arr[0]; if(n>1) { dp[1] = Math.Max(arr[0], arr[1]); } for (int i= 2;i
Understood! Thanks a lot! Could someone tell me what to do if we are required to return the list of houses (whether indices or the amount) that we chose for our solution.
In space optimisation approach there is no need to check the condition as the index can not be negative and we have create a variable that is prev2 for index = -1
why are we not summing odd and even elements and then returning the max of those ?.... Apart from this doubt I wanna thank you for making such amazing videos for Dynamic Programming....
i solved it basic (get the logic of pic and not pic just because i watch your recursion playlist) part own just missed one edge case and dp[ind-2] and get in first few min
In the house robber problem from leetcode taking example 2,7,9,3,1 on the outline made me to think that if we take alternating number then identify the maximum sum subsequence. But the actual solution is like at every index we need to take maximum amount. Understood this context from your video but can guide me with the tip in the problem statement where is it mentioned or how to identify that here dynamic approach has to considered.
In this tabulation approach we consider max by picking a[i]+dp[i-2], now you may ask we can also take a[i]+dp[i-1], why? because lets say dp[i-1] is made by not picking a[i-1] so you can consider dp[i-1] but there is no need as it is redundant because if dp[i-1] is max sum till index i-1 without considering nums[i-1], it means it definitely picked a[i-2](as all are positive numbers)so dp[i-2] will be same as dp[i-1] in that case.