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

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • Lecture Notes/C++/Java Codes: takeuforward.org/data-structu...
    Problem Link: bit.ly/3q5rlUY
    Make sure to join our telegram group for discussions: linktr.ee/takeUforward
    Pre-req for this Series: • Re 1. Introduction to ...
    Full Playlist: • Striver's Dynamic Prog...
    In this video, we have discussed how to solve the problem of the maximum sum without taking adjacent elements. Here the concept of pick non pick has been explained.
    If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.org/interviews/s...
    You can also get in touch with me at my social handles: linktr.ee/takeUforward

Komentáře • 3,7K

  • @takeUforward
    @takeUforward  Před 2 lety +401

    I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you.

  • @ankitadas5833
    @ankitadas5833 Před 2 lety +220

    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  Před 2 lety +64

      Thanks 😊

    • @YahyaMohammed-gh7np
      @YahyaMohammed-gh7np Před 5 měsíci

      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.

  • @shetty-m4d
    @shetty-m4d Před 4 dny +2

    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❤

  • @md.imrankhan6912
    @md.imrankhan6912 Před 10 měsíci +1

    An absolute living legend! Your content is truly remarkable and deserving of endless likes and a multitude of subscribers. Keep up the incredible work.

    • @thisismr900
      @thisismr900 Před 10 měsíci

      legend is like bhagat singh , freedom frighters .
      Striver is a very hardworking guy.

  • @anuragprasad6116
    @anuragprasad6116 Před rokem +48

    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!

  • @decepticonWave
    @decepticonWave Před 11 měsíci +16

    I love it when you get so excited and start speaking your native language.
    You are amazing striver

  • @user-fb1yo8fb3i
    @user-fb1yo8fb3i Před 6 měsíci +1

    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.

  • @DuyPham-sq5qe
    @DuyPham-sq5qe Před 3 měsíci

    The way he teaches is detailed and easy to understand. Thanks a lot!!!

  • @akashsardar495
    @akashsardar495 Před 2 lety +31

    This is indeed the best DP series. Thanks for providing such quality content for free. I'm really enjoying it.

  • @deepakojha3216
    @deepakojha3216 Před 2 lety +37

    what an energy man....!!! ❤The way you teach make me fall in love with the programming .....!!

  • @neharathod637
    @neharathod637 Před 5 měsíci

    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!

  • @aakashshivanshu3578
    @aakashshivanshu3578 Před 8 měsíci

    Thanks you striver for such an amazing tutorial. Your recursion playlist and now this DP series is building an amazing confidence inside me .Now I feel that I can solve the DP problems easily.

  • @abhinavgupta5641
    @abhinavgupta5641 Před rokem +12

    The energy while teaching is just awesome man even a sleepy head can understand the concept u teaches, Hats off!❤

  • @user-nq7nt1rq9b
    @user-nq7nt1rq9b Před 2 lety +34

    This is my 1St comment on this channel
    Really he is explaining the thought process which should be come when we are solving problems

  • @rohangupta4290
    @rohangupta4290 Před 4 měsíci +1

    Man you are a genius when it comes to teaching!!

  • @anusuyaganguly6009
    @anusuyaganguly6009 Před 9 měsíci

    us. understood in one go ! and DP never seemed so easy before this video . keep up the good work.

  • @aprekshamathur6143
    @aprekshamathur6143 Před 2 lety +8

    thank u for this dp series. It's actually clearing my concepts.

  • @eshupatel3902
    @eshupatel3902 Před 2 lety +5

    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😇

  • @anoopsingh36
    @anoopsingh36 Před 5 měsíci +2

    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.

  • @TurboTalesShortsYT
    @TurboTalesShortsYT Před 3 měsíci +1

    ur teaching method is just awesome....no one in the entire CZcams world has made such a best video on DSA. lots of love from my side.🤟🥰

  • @surabhsaxena7928
    @surabhsaxena7928 Před 2 lety +6

    Your enthusiasm and energy grabs my entire focus on the topic🔥🔥.. thank you for the series🙏🙏
    "understood"

  • @abirhussain6033
    @abirhussain6033 Před rokem +6

    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.

  • @sudhanshuraj8080
    @sudhanshuraj8080 Před 6 měsíci

    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!

  • @varadpanchal1231
    @varadpanchal1231 Před měsícem +1

    BEST DP PLAYLIST EVER

  • @divyaporwal589
    @divyaporwal589 Před 2 lety +3

    Best playlist ever of dp....and you have proved it✌️

  • @phatcat7924
    @phatcat7924 Před rokem +3

    This is the best dp series of all time. Thank you striver for all the efforts you put in this.

  • @user-ho7zu2mi7c
    @user-ho7zu2mi7c Před 6 měsíci

    Understood !!
    I know you are striver but for us you are a saviour..!

  • @nourhanessam9633
    @nourhanessam9633 Před 8 měsíci

    Words are not enough to describe this perfect explanation, keep going please.

  • @chetanraghavv
    @chetanraghavv Před 2 lety +3

    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!

  • @adarshanku7988
    @adarshanku7988 Před 2 lety +5

    Instead of adding base case as if(ind

    • @shreyaagarwal6746
      @shreyaagarwal6746 Před 2 měsíci

      I was struggling with this basecase and was missing to apply the max method considering the arr[0] too. Thanks for commenting this out.

  • @KaushalDhruw
    @KaushalDhruw Před 3 měsíci

    Your explanation is amazing, and your enthusiasm.. contagious. Can't thank you enough man.

  • @AmitVerma-iq3oe
    @AmitVerma-iq3oe Před 10 měsíci

    your efforts are priceless thanks for making such content, you are a true educator.

  • @aryangupta9062
    @aryangupta9062 Před 11 měsíci +6

    Striver has to be the craziest guy, came here to get through placements ended up wanting to code for fun!!! Understood concept very well!!

  • @khushisingh6651
    @khushisingh6651 Před 2 lety +4

    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 🥰🤩

  • @aakashyadav8142
    @aakashyadav8142 Před 8 měsíci

    Understood and very much liked you teaching technic. I admit you as a role model.🔥🔥🔥
    Awesome sir

  • @stith_pragya
    @stith_pragya Před 6 měsíci +1

    UNDERSTOOD............Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @SHASHANKRUSTAGII
    @SHASHANKRUSTAGII Před 2 lety +150

    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.

  • @bhagyabeebaruah4900
    @bhagyabeebaruah4900 Před 2 lety +9

    Falling in love with programming ❤️ all credit goes to you ..the way you teach is just🔥🔥

  • @mathy642
    @mathy642 Před 6 měsíci

    Hey Striver,
    The way you are explaining is really awesome and it is helping us to solve on our own :)

  • @birjeshgupta2003
    @birjeshgupta2003 Před 5 měsíci

    UnderStood , u are literally teaching in very nice manner.

  • @devankmaheshwari2712
    @devankmaheshwari2712 Před rokem +8

    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

  • @KuldeepSingh-ru9ok
    @KuldeepSingh-ru9ok Před 2 lety +8

    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)

  • @thisismr900
    @thisismr900 Před 10 měsíci

    I have watched your 4 DP lectures
    and trust me
    I was able to solve this question in in one go.
    even pehli bar DP touch kiya , from today itself
    This is your contri !
    US!!!

  • @biswajitsaha6773
    @biswajitsaha6773 Před 5 měsíci

    Fully understood dada, your explanation is more than enough to write the actual code by ourselves!

  • @parthsalat
    @parthsalat Před 2 lety +5

    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 Před 20 dny

      bruh, prev2 needs to be 0 because also if the negative check is omitted it'll work fine.

  • @karthikeyansivakkumar5075

    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  Před 2 lety +13

      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 Před 2 lety

      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 Před 2 lety +8

      @@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

  • @idocoding2003
    @idocoding2003 Před 7 měsíci +1

    Sir.... You are legend... Only one word to describe you

  • @vidyotma6043
    @vidyotma6043 Před 9 měsíci

    Understood sir, Your content is really of very good quality and make us how we can analyze the problem and think of approach. Really appreciable.... Thankyou sir

  • @beinghappy9223
    @beinghappy9223 Před 2 lety +7

    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

  • @gajjalaharsha
    @gajjalaharsha Před 2 lety +7

    Can we write base case for 1 if(n==1) return max(a[0], a[1])

    • @lesGo.8963
      @lesGo.8963 Před 2 lety

      yes but that is only if the size of the vector is more than 1

  • @bhupendramaurya6587
    @bhupendramaurya6587 Před 6 měsíci

    Understood bhaiya with so much clarity, Thank you so much for providing content like this. Thank you again bhaiya

  • @karthikk2316
    @karthikk2316 Před 5 měsíci

    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❤

  • @suyashjain3223
    @suyashjain3223 Před 8 měsíci

    Amazing Explanation Striver!! Understood all the concepts taught in the video.

  • @user-xq1ee8zy3k
    @user-xq1ee8zy3k Před 9 měsíci

    Understood .Quality teaching bro.Thank u so much.

  • @arastusharma439
    @arastusharma439 Před 5 měsíci

    Understood !!! Amazing Lecture 👌

  • @AppaniMadhavi
    @AppaniMadhavi Před měsícem

    Understood and solved on my own, thank you striver for the amazing lectures!!!

  • @anuj.gupta__
    @anuj.gupta__ Před 15 dny

    Wow man!! Understood everything

  • @Anonymous-th8sg
    @Anonymous-th8sg Před 6 měsíci

    sir watching now, and we support you for this wonderful content you are making for us. Much love sir❤

  • @shigoeditz7079
    @shigoeditz7079 Před 21 dnem

    Understood !!!!! Thankyou so much Striver

  • @codecrafts5263
    @codecrafts5263 Před 6 měsíci

    Understood. I watched this question on some other youtube channel but this one was far better.

  • @deepakbhatt555
    @deepakbhatt555 Před 7 měsíci

    Thanks for these kind of videos. It is helping a lot.

  • @deepikabinjola2084
    @deepikabinjola2084 Před 5 měsíci

    understood completely😊 as your way of teaching is amazing !!👏

  • @anshikagupta5858
    @anshikagupta5858 Před 7 měsíci

    Thankyou so much Striver😊

  • @sahilrepuriya3205
    @sahilrepuriya3205 Před 3 měsíci

    Understood , now dp seems easy to me thank you so much sir 💙

  • @user-zm9qn2sp3h
    @user-zm9qn2sp3h Před 9 měsíci

    Thanks for providing such quality content for free. "understood".

  • @babitakumari2172
    @babitakumari2172 Před 2 měsíci

    Solved it myself , thanku so much to make the dp concept easy

  • @shriRadheHariom
    @shriRadheHariom Před dnem

    Great explanation Sir, You teach each and every concept with accuracy.Thanks a lot.

  • @yogeshrajput6331
    @yogeshrajput6331 Před 4 měsíci

    amazing explaination what a style of teaching

  • @RohitVerma-yb4ch
    @RohitVerma-yb4ch Před 9 měsíci

    Thanks!! I am finally understanding DP :D

  • @raghavmanish24
    @raghavmanish24 Před 27 dny

    you are legend for dp playlist

  • @user-bt6mh9ez3u
    @user-bt6mh9ez3u Před 4 dny

    Understood!!Amazing Videos

  • @nikunjsoni123
    @nikunjsoni123 Před 2 měsíci

    Understood: wonderful explanation! Thank you Sir!

  • @preetisahani5054
    @preetisahani5054 Před 9 měsíci

    Understood, awesome explanation.

  • @ShreyaKarn-q2f
    @ShreyaKarn-q2f Před 7 dny

    "Understood". Another amazing lecture!!

  • @cricket-lo8fk
    @cricket-lo8fk Před 9 měsíci

    understood ,Awesome explanation❤❤❤

  • @surajpalsau870
    @surajpalsau870 Před 10 měsíci

    I found the best DP playlist ever, free or paid. understood sir

  • @stain0p101
    @stain0p101 Před 10 měsíci

    Understood the whole concept. Awesome video sir.

  • @aruna5869
    @aruna5869 Před 6 měsíci +1

    @25:18 Intro to space optimisation🔥😂❤.Thank you very much. Crystal clear explanation❤🙏

  • @harshkoshti4588
    @harshkoshti4588 Před 4 měsíci

    Finally i understood how recursion is working in this program 😊

  • @UECAshutoshKumar
    @UECAshutoshKumar Před 5 měsíci +1

    Thank you sir 🙏
    Understood!!

  • @shubhamc183
    @shubhamc183 Před 5 měsíci

    thanks a ton for your efforts! ❤

  • @pardhi8959
    @pardhi8959 Před 3 měsíci

    Salute for your hard work

  • @raaviumasusmitha937
    @raaviumasusmitha937 Před měsícem

    @striver your efforts are really amazing!

  • @elvishsharma8137
    @elvishsharma8137 Před 8 měsíci

    Thanks for this amazing content 😍

  • @NazeerBashaShaik
    @NazeerBashaShaik Před 7 měsíci

    Thanks for great explanation.

  • @ObitoXuchiha942
    @ObitoXuchiha942 Před 11 měsíci +1

    Loved it !!

  • @VivekSharma-eh2tv
    @VivekSharma-eh2tv Před 10 dny

    the space optimization is the so good , i feel so understood .

  • @AbhishekKumar-cv1dh
    @AbhishekKumar-cv1dh Před 8 měsíci

    Understood beautifully!!!!! ❤‍🔥❤‍🔥❤‍🔥❤‍🔥❤‍🔥

  • @Abcd-jt1qs
    @Abcd-jt1qs Před měsícem

    Understood sir! Thank you for these amazing lectures :)

  • @user-qq5bb7bh5z
    @user-qq5bb7bh5z Před 9 měsíci

    hats off to your efforts

  • @sanskritisharma8831
    @sanskritisharma8831 Před 8 měsíci

    great as always

  • @UnnatiMishra-hb6he
    @UnnatiMishra-hb6he Před měsícem

    Amazing Lecture!!!!

  • @sujalgangrade7333
    @sujalgangrade7333 Před 3 měsíci

    Really Amazing explanation I am able to understand each and every concept very clearly 😇😇

  • @nourhanessam9633
    @nourhanessam9633 Před 7 měsíci

    Amazing explanations, keep going please.

  • @satyamgade2043
    @satyamgade2043 Před 9 měsíci

    "US" .... absolutely the best teacher ❤

  • @akankshaverma9999
    @akankshaverma9999 Před 10 dny

    Amazing content. Thanks alot

  • @user-ke7fs7ds6h
    @user-ke7fs7ds6h Před 6 měsíci

    understood sir, great job

  • @rajatraj4297
    @rajatraj4297 Před 10 měsíci

    This question made me realize that striver's series are really building my logic as I solved this problem using technique i learned in Backtracking playlist.

  • @manasansh7198
    @manasansh7198 Před 9 měsíci

    Understood Striver great effort from your side

  • @Upscwithconsistency2025
    @Upscwithconsistency2025 Před 8 měsíci

    understood sir...great explaination.