Тёмный

DP 5. Maximum Sum of Non-Adjacent Elements | House Robber | 1-D | DP on Subsequences 

take U forward
Подписаться 692 тыс.
Просмотров 420 тыс.
50% 1

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 4 тыс.   
@takeUforward
@takeUforward 2 года назад
I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you.
@aakashagarwal146
@aakashagarwal146 2 года назад
Understood bro
@dhrubajyoti3774
@dhrubajyoti3774 2 года назад
Understood 🥺
@tcob33yashambekar48
@tcob33yashambekar48 2 года назад
Understood 👍👍
@kunjparekh4632
@kunjparekh4632 2 года назад
Understood
@jasmeenkaur6001
@jasmeenkaur6001 2 года назад
Understood😁
@ramyasri5452
@ramyasri5452 Месяц назад
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🎈
@divyareddy7622
@divyareddy7622 21 день назад
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 ?
@abhishekjain3344
@abhishekjain3344 10 дней назад
@@divyareddy7622 depends on your pace, generally speaking it should take around 1 month
@topg-fg5fu
@topg-fg5fu 2 часа назад
@@abhishekjain3344 entire playlist or just dp one
@ankitadas5833
@ankitadas5833 2 года назад
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.
@takeUforward
@takeUforward 2 года назад
Thanks 😊
@YahyaMohammed-gh7np
@YahyaMohammed-gh7np 9 месяцев назад
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.
@anoopsingh36
@anoopsingh36 8 месяцев назад
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.
@decepticonWave
@decepticonWave Год назад
I love it when you get so excited and start speaking your native language. You are amazing striver
@anuragprasad6116
@anuragprasad6116 Год назад
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!
@dharssinikarthikeyan4760
@dharssinikarthikeyan4760 11 месяцев назад
Thanks for this comment, I was confused and noticed only after you say!
@user-nq7nt1rq9b
@user-nq7nt1rq9b 2 года назад
This is my 1St comment on this channel Really he is explaining the thought process which should be come when we are solving problems
@TurboTalesShortsYT
@TurboTalesShortsYT 7 месяцев назад
ur teaching method is just awesome....no one in the entire RU-vid world has made such a best video on DSA. lots of love from my side.🤟🥰
@adarshanku7988
@adarshanku7988 2 года назад
Instead of adding base case as if(ind
@shreyaagarwal6746
@shreyaagarwal6746 5 месяцев назад
I was struggling with this basecase and was missing to apply the max method considering the arr[0] too. Thanks for commenting this out.
@deepakojha3216
@deepakojha3216 2 года назад
what an energy man....!!! ❤The way you teach make me fall in love with the programming .....!!
@akashsardar495
@akashsardar495 2 года назад
This is indeed the best DP series. Thanks for providing such quality content for free. I'm really enjoying it.
@057ahmaransari5
@057ahmaransari5 2 месяца назад
what a content it's amazing . DP becomes easy for me till now because of you. Thank you so much.
@eshupatel3902
@eshupatel3902 2 года назад
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😇
@chetanraghavv
@chetanraghavv 2 года назад
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!
@shetty-m4d
@shetty-m4d 3 месяца назад
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❤
@RidhikaGarg-r8t
@RidhikaGarg-r8t 9 месяцев назад
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.
@SHASHANKRUSTAGII
@SHASHANKRUSTAGII 2 года назад
The way you explain na, aisa lagta hai ki you yourself enjoy this, and that is why your basics are so clear. Keep it up. Google ka CEO banoge ek din.
@dineshchoudhary8635
@dineshchoudhary8635 Год назад
@@utkarshsharma6650 app bi
@Bharat_Rider
@Bharat_Rider 10 месяцев назад
US
@eklavya22k34
@eklavya22k34 8 месяцев назад
So TRUE. Striver enjoys coding. Coding is Fun for many geeks.
@abirhussain6033
@abirhussain6033 Год назад
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.
@abhinavgupta5641
@abhinavgupta5641 2 года назад
The energy while teaching is just awesome man even a sleepy head can understand the concept u teaches, Hats off!❤
@biswajitsaha6773
@biswajitsaha6773 8 месяцев назад
Fully understood dada, your explanation is more than enough to write the actual code by ourselves!
@KuldeepSingh-ru9ok
@KuldeepSingh-ru9ok 2 года назад
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)
@surabhsaxena7928
@surabhsaxena7928 2 года назад
Your enthusiasm and energy grabs my entire focus on the topic🔥🔥.. thank you for the series🙏🙏 "understood"
@aryangupta9062
@aryangupta9062 Год назад
Striver has to be the craziest guy, came here to get through placements ended up wanting to code for fun!!! Understood concept very well!!
@Bhagsrocks
@Bhagsrocks Месяц назад
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!!!
@bhagyabeebaruah4900
@bhagyabeebaruah4900 2 года назад
Falling in love with programming ❤️ all credit goes to you ..the way you teach is just🔥🔥
@aprekshamathur6143
@aprekshamathur6143 2 года назад
thank u for this dp series. It's actually clearing my concepts.
@karthikeyansivakkumar5075
@karthikeyansivakkumar5075 2 года назад
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.
@takeUforward
@takeUforward 2 года назад
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.
@aakashagarwal146
@aakashagarwal146 2 года назад
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
@shaamidrees6036
@shaamidrees6036 2 года назад
@@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
@shreyajain5058
@shreyajain5058 2 месяца назад
"US"❤ the only channel which makes me understand all these problems so easily. Thankyou so much sir!!
@parthsalat
@parthsalat 2 года назад
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.
@googlewasmyidea9895
@googlewasmyidea9895 3 месяца назад
bruh, prev2 needs to be 0 because also if the negative check is omitted it'll work fine.
@devankmaheshwari2712
@devankmaheshwari2712 Год назад
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
@khushisingh6651
@khushisingh6651 2 года назад
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 🥰🤩
@TheAI-Tutor
@TheAI-Tutor 9 месяцев назад
Kya haal hai khushi 😏
@sudhanshuraj8080
@sudhanshuraj8080 9 месяцев назад
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!
@beinghappy9223
@beinghappy9223 2 года назад
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
@AbhishekSingh-hi5eq
@AbhishekSingh-hi5eq Год назад
House robber problem on leetcode
@gajjalaharsha
@gajjalaharsha 2 года назад
Can we write base case for 1 if(n==1) return max(a[0], a[1])
@lesGo.8963
@lesGo.8963 2 года назад
yes but that is only if the size of the vector is more than 1
@ManishKumar-rt5yn
@ManishKumar-rt5yn 21 день назад
Never ever seen a teacher or bhaiya like you just amazing ❤❤❤❤❤❤
@rohangupta4290
@rohangupta4290 7 месяцев назад
Man you are a genius when it comes to teaching!!
@DuyPham-sq5qe
@DuyPham-sq5qe 7 месяцев назад
The way he teaches is detailed and easy to understand. Thanks a lot!!!
@KaushalDhruw
@KaushalDhruw 6 месяцев назад
Your explanation is amazing, and your enthusiasm.. contagious. Can't thank you enough man.
@mendahaseena7901
@mendahaseena7901 2 месяца назад
your way of solving DP problems really helpful for me. Thanks a lot
@shriRadheHariom
@shriRadheHariom 3 месяца назад
Great explanation Sir, You teach each and every concept with accuracy.Thanks a lot.
@aruna5869
@aruna5869 9 месяцев назад
@25:18 Intro to space optimisation🔥😂❤.Thank you very much. Crystal clear explanation❤🙏
@nikunjsoni123
@nikunjsoni123 5 месяцев назад
Understood: wonderful explanation! Thank you Sir!
@codecrafts5263
@codecrafts5263 10 месяцев назад
Understood. I watched this question on some other youtube channel but this one was far better.
@karthikk2316
@karthikk2316 8 месяцев назад
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❤
@stith_pragya
@stith_pragya 9 месяцев назад
UNDERSTOOD............Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@birjeshgupta2003
@birjeshgupta2003 8 месяцев назад
UnderStood , u are literally teaching in very nice manner.
@ABHIMANYUTHAPLIYAL
@ABHIMANYUTHAPLIYAL 3 месяца назад
"US" what the heck man, that space optimization is just superbb. thankyou so much striver.
@bhupendramaurya6587
@bhupendramaurya6587 9 месяцев назад
Understood bhaiya with so much clarity, Thank you so much for providing content like this. Thank you again bhaiya
@bmishra98
@bmishra98 3 месяца назад
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; }
@neshrochwani9934
@neshrochwani9934 2 месяца назад
Understood perfectly, It has been so easy now to convert recursive code to Memoization, Tabulation and then space optimization approach Thanks A Lottt!!!!
@AppaniMadhavi
@AppaniMadhavi 4 месяца назад
Understood and solved on my own, thank you striver for the amazing lectures!!!
@neharathod637
@neharathod637 8 месяцев назад
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!
@LaxmiTeja-c2f
@LaxmiTeja-c2f 9 месяцев назад
Understood !! I know you are striver but for us you are a saviour..!
@sujalgangrade7333
@sujalgangrade7333 7 месяцев назад
Really Amazing explanation I am able to understand each and every concept very clearly 😇😇
@prajaktagharal6258
@prajaktagharal6258 2 месяца назад
The way you teach..omg!! I just love it❤
@deepikabinjola2084
@deepikabinjola2084 8 месяцев назад
understood completely😊 as your way of teaching is amazing !!👏
@roshankarn7979
@roshankarn7979 2 месяца назад
love babbar bhaiya of channel code help explains space optimization sir. He also explains it very well.
@ShreyaKarn-q2f
@ShreyaKarn-q2f 3 месяца назад
"Understood". Another amazing lecture!!
@HarishSG-z7b
@HarishSG-z7b 8 месяцев назад
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
@yogeshrajput6331
@yogeshrajput6331 7 месяцев назад
amazing explaination what a style of teaching
@babitakumari2172
@babitakumari2172 5 месяцев назад
Solved it myself , thanku so much to make the dp concept easy
@idocoding2003
@idocoding2003 10 месяцев назад
Sir.... You are legend... Only one word to describe you
@parthib.1555
@parthib.1555 10 месяцев назад
Understood !! btw I just wanna tell Dada and I are from the same college.
@ParodyCSEDept
@ParodyCSEDept 6 месяцев назад
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.
@VivekSharma-eh2tv
@VivekSharma-eh2tv 3 месяца назад
the space optimization is the so good , i feel so understood .
@sahilrepuriya3205
@sahilrepuriya3205 6 месяцев назад
Understood , now dp seems easy to me thank you so much sir 💙
@varadpanchal1231
@varadpanchal1231 4 месяца назад
BEST DP PLAYLIST EVER
@jerrry_coder6443
@jerrry_coder6443 Месяц назад
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
@amandubey9296
@amandubey9296 5 месяцев назад
Thank You Soo much Sir, I went for to much resourse to learn DP but your playlist is just awesome🙂. "US"
@Anonymous-th8sg
@Anonymous-th8sg 9 месяцев назад
sir watching now, and we support you for this wonderful content you are making for us. Much love sir❤
@PriyanshiAgrawal-h4z
@PriyanshiAgrawal-h4z 14 дней назад
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....
@prashantyadav7823
@prashantyadav7823 2 дня назад
it will fail for 2 1 1 2
@MayurChawda-v4e
@MayurChawda-v4e 10 месяцев назад
Great explanation Striver, but why did you start from last index?
@sonuanand167
@sonuanand167 4 месяца назад
Understand.. striver (Raj).. Bhai gajab..
@anonymous5946
@anonymous5946 7 месяцев назад
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
@karthikeyanbaluchamy3496
@karthikeyanbaluchamy3496 4 месяца назад
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.
@harshkoshti4588
@harshkoshti4588 7 месяцев назад
Finally i understood how recursion is working in this program 😊
@deepakbhatt555
@deepakbhatt555 10 месяцев назад
Thanks for these kind of videos. It is helping a lot.
@karandeeplamba5027
@karandeeplamba5027 Месяц назад
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.
@ashwaniagrawal27
@ashwaniagrawal27 Месяц назад
incredible explaination striver
@KapilMaan-vw9sd
@KapilMaan-vw9sd Месяц назад
understood, very great video sir !!!
@arastusharma439
@arastusharma439 9 месяцев назад
Understood !!! Amazing Lecture 👌
@shigoeditz7079
@shigoeditz7079 4 месяца назад
Understood !!!!! Thankyou so much Striver
@tsk1217
@tsk1217 9 месяцев назад
Thankyou Bhaiya for this type of explaination , It helps me a Lot Lots ......... ❤ Understood
@raaviumasusmitha937
@raaviumasusmitha937 4 месяца назад
@striver your efforts are really amazing!
@mathy642
@mathy642 9 месяцев назад
Hey Striver, The way you are explaining is really awesome and it is helping us to solve on our own :)
@alialrafei
@alialrafei 6 месяцев назад
good job but the if condition for if(I>1) is not necessary at all because prev2 is zero at the start
@Abcd-jt1qs
@Abcd-jt1qs 4 месяца назад
Understood sir! Thank you for these amazing lectures :)
@imtiyazalam_IIItian
@imtiyazalam_IIItian 4 месяца назад
thank you so much bhaiya for this amazing playlist
@dewsara2888
@dewsara2888 3 месяца назад
Thanks a lot. You are awesome. Understood very well.
@akankshaverma9999
@akankshaverma9999 3 месяца назад
Amazing content. Thanks alot
@kishugupta9564
@kishugupta9564 8 месяцев назад
The way you teach make me fall in love with the programming .....!!
@vasanthi_chitturi__
@vasanthi_chitturi__ 2 месяца назад
Amazing Lecture!!!
@nourhanessam9633
@nourhanessam9633 10 месяцев назад
Amazing explanations, keep going please.
@akbuddyeditors
@akbuddyeditors 5 месяцев назад
with due respect, Love babbar also teaches space optimization, but your explanation is better.
@random_akki
@random_akki 3 месяца назад
Thanks a lot bhaiya was able to solve it by my own
@dreamerblack9006
@dreamerblack9006 21 день назад
Great Course. TY so much!
@raghavmanish24
@raghavmanish24 4 месяца назад
you are legend for dp playlist
@anonymousboy2868
@anonymousboy2868 4 месяца назад
us. Thank you so much for wonderful explanation
@NaveenPGForYou
@NaveenPGForYou 10 дней назад
Understood, Thanks Striver!!
@nitishaverma6557
@nitishaverma6557 Месяц назад
i was getting afraid from DP in vain , it seems to be quite easy and interesting to me !!
@SOUVIK-po9jt
@SOUVIK-po9jt Месяц назад
@@nitishaverma6557 Which college do u study
Далее
DP 6. House Robber 2 | 1D DP | DP on Subsequences
9:50
If you can solve this, you can be an engineer.
8:40
Просмотров 16 тыс.
The Wordpress drama keeps getting worse
12:47
Просмотров 96 тыс.
How I Mastered Data Structures and Algorithms
10:45
Просмотров 209 тыс.