House Robber (LeetCode 198) | Full solution with diagrams | Easy explanation | Study Algorithms

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ค. 2024
  • To find an efficient solution to such problems, always try to break down into smaller segments. That is how dynamic programming works. Use the solution of the smaller segment to extend your solution to the larger problem as you go on iterating. Watch this video to understand how can you achieve the maximum loot along with beautiful diagrams and a dry-run of code in JAVA.
    Actual problem on LeetCode: leetcode.com/problems/house-r...
    Chapters:
    00:00 - Intro
    00:52 - Problem Statement and Description
    02:32 - Brute Force & Greedy Approach
    05:12 - How to attack such problems
    07:31 - Application of logic
    11:03 - Dry-run of Code
    13:08 - Final Thoughts
    📚 Links to topics I talk about in the video:
    Brute Force Algorithms: • Brute Force algorithms...
    Dynamic Programming: • Dynamic Programming ea...
    Greedy Algorithms: • Greedy Algorithms with...
    📘 A text based explanation is available at: studyalgorithms.com
    Code on Github: github.com/nikoo28/java-solut...
    Test-cases on Github: github.com/nikoo28/java-solut...
    📖 Reference Books:
    Starting Learn to Code: amzn.to/36pU0JO
    Favorite book to understand algorithms: amzn.to/39w3YLS
    Favorite book for data structures: amzn.to/3oAVBTk
    Get started for interview preparation: amzn.to/39ysbkJ
    🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
    🎥 My Recording Gear:
    Recording Light: amzn.to/3pAqh8O
    Microphone: amzn.to/2MCX7qU
    Recording Camera: amzn.to/3alg9Ky
    Tablet to sketch and draw: amzn.to/3pM6Bi4
    Surface Pen: amzn.to/3pv6tTs
    Laptop to edit videos: amzn.to/2LYpMqn
    💻 Get Social 💻
    Follow on Facebook at: / studyalgos
    Follow on Twitter at: / studyalgorithms
    Follow on Tumblr at: / studyalgos
    Subscribe to RSS feeds: studyalgorithms.com/feed/
    Join fan mail: eepurl.com/g9Dadv
    #leetcode #dynamicprogramming #interview

ความคิดเห็น • 92

  • @manojtate9604
    @manojtate9604 5 หลายเดือนก่อน +15

    Top-notch explanation available on TH-cam, thanks!

  • @zeltrax00
    @zeltrax00 8 หลายเดือนก่อน +5

    I used chatgpt to generate solution but I cannot understand it. After watch this video, I understand every single line of the chatgpt code. You're the best

  • @KodeWithKaran
    @KodeWithKaran 5 หลายเดือนก่อน +5

    finally i can sleep peacefully now...what an explaination. just wow... Thanks man!!!

    • @nikoo28
      @nikoo28  4 หลายเดือนก่อน +1

      Great to hear!

  • @carl1809
    @carl1809 6 หลายเดือนก่อน +2

    Amazing explanation. I was looking everywhere why this works and you manage to explain it in a way that clicked

  • @papercut._.
    @papercut._. 6 หลายเดือนก่อน +2

    bro you're a legend I can usually come up with memoization you're way of explaning made it easy for me to translate my understanding to tabulation. thanks a lot!

  • @010101dddm
    @010101dddm ปีที่แล้ว +8

    Best explanation on you tube, thank you

  • @surendhar.v4952
    @surendhar.v4952 ปีที่แล้ว +7

    Nikhil , You don't know , How you inspired me in teaching the problem and making the things simple and crisp.
    I really love the way how you taught your final thoughts.
    Gained some inspiration as well as the solution.
    Keep rocking Nikhil 🔥.

  • @hari7110
    @hari7110 5 หลายเดือนก่อน +4

    Bro your explanation is just awesome!! u explained each step in detail

  • @siddharthmehta4223
    @siddharthmehta4223 11 หลายเดือนก่อน +4

    dayum...... awesome explanation brother. bows down. live long Nikhil.

  • @varoonsb
    @varoonsb 3 วันที่ผ่านมา

    Thank you so much! First time seeing someone explaining solution as good as NeetCode1

  • @qR7pK9sJ2t
    @qR7pK9sJ2t 6 หลายเดือนก่อน +1

    Excellent.. The best explanation on utube !

  • @TalesOfGranny
    @TalesOfGranny 6 หลายเดือนก่อน +2

    Very well explained. U have knack of teaching

  • @daffapradana8557
    @daffapradana8557 ปีที่แล้ว

    The best explanation that i have ever found! thank u so much

  • @gojosatoru988
    @gojosatoru988 ปีที่แล้ว +1

    Very to understand explanation, Loved it.

  • @kamalasowmya7120
    @kamalasowmya7120 5 หลายเดือนก่อน +1

    thank you for breaking this down! :)

  • @badrinarayanans355
    @badrinarayanans355 6 หลายเดือนก่อน +1

    Clearly explained, thankyou.

  • @rajeshpaithari7320
    @rajeshpaithari7320 2 หลายเดือนก่อน

    Great logic and great explanation! Expecting more videos.

  • @rishichansauria3658
    @rishichansauria3658 ปีที่แล้ว +5

    The way you explain is just awesome..please don’t stop.. after going through your videos I’m in love with DP ..thanku so much.

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      That is so amazing to hear 🤩

    • @serg1778
      @serg1778 11 หลายเดือนก่อน

      @@nikoo28 really awesome )

  • @makethemostOfwhatYouGot
    @makethemostOfwhatYouGot 2 หลายเดือนก่อน

    Incredible stuff !

  • @abhisheknandann
    @abhisheknandann ปีที่แล้ว +1

    Great video boss!

  • @lucianpetriuc7373
    @lucianpetriuc7373 4 หลายเดือนก่อน +1

    Leetcode is art and you're Picasso. Incredible explanation Nikhil!

  • @khyatikakkar9259
    @khyatikakkar9259 หลายเดือนก่อน

    Amazing explanation !!

  • @adityamaurya554
    @adityamaurya554 3 หลายเดือนก่อน

    ek no bhai

  • @puneetchhabra2578
    @puneetchhabra2578 ปีที่แล้ว

    Thankyou sir!!
    Great Explaination, beginners friendly.

  • @unknownman1
    @unknownman1 7 หลายเดือนก่อน +1

    No words. Simply wow!!!

    • @nikoo28
      @nikoo28  6 หลายเดือนก่อน +1

      your comment - "just looking like a wow"..thanks for the support.

  • @ghanashrim2839
    @ghanashrim2839 ปีที่แล้ว

    This is the best I've seen anyone explain the problem. Thank you so much yaar.

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      always happy to have you as my audience :)

  • @jus3472
    @jus3472 5 หลายเดือนก่อน +1

    Great explanation thank you.

  • @RohitSharma-mg3np
    @RohitSharma-mg3np 5 หลายเดือนก่อน +1

    Subscribed , Nice Explaination

  • @ramswrooppatidar7599
    @ramswrooppatidar7599 5 หลายเดือนก่อน +1

    wow just a amazing , explaination great work

  • @anonymous-ze5fg
    @anonymous-ze5fg ปีที่แล้ว +1

    Your contents are great, highly appreciated , Please keep uploading more interesting problems.. Thanks

    • @nikoo28
      @nikoo28  ปีที่แล้ว +2

      More to come!

  • @YashRekha594
    @YashRekha594 7 หลายเดือนก่อน

    Thank you very much for the well-explained video 👍

  • @mukeshperiyasamy3364
    @mukeshperiyasamy3364 ปีที่แล้ว

    Great explanation, Thank you for sharing your knowledge.

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      My pleasure!

  • @rogerthat7190
    @rogerthat7190 11 หลายเดือนก่อน +1

    Thank you!!

  • @user-fk2xu3fh5r
    @user-fk2xu3fh5r 7 หลายเดือนก่อน

    Brother thank you so much 🥺❤ now I understand after you drawing those pictures

  • @jishnus1526
    @jishnus1526 8 หลายเดือนก่อน

    Excellent explanation 🤩

  • @manishbarnawal2865
    @manishbarnawal2865 4 หลายเดือนก่อน

    My First watch of this channel video !! Great explanation !! This I call as a social service which any one can avail in this country and will remember your explanation !! Subscribed !!

    • @nikoo28
      @nikoo28  3 หลายเดือนก่อน

      thanks for the sub!!

  • @kunalkheeva
    @kunalkheeva 10 หลายเดือนก่อน

    it really helped bro!

  • @DilshadAhmad-pc1tm
    @DilshadAhmad-pc1tm 5 หลายเดือนก่อน +1

    Bro..U r tooo good.. The way u explained is awesome, super. Please keep it up...

  • @yomamasofat413
    @yomamasofat413 26 วันที่ผ่านมา +1

    omg my brain is physically hurting from this...

  • @jayprajapati9
    @jayprajapati9 ปีที่แล้ว +1

    best explanation

  • @504rishukumar4
    @504rishukumar4 5 หลายเดือนก่อน

    Nice Explanation,

  • @mock1112
    @mock1112 ปีที่แล้ว

    Amazing video

  • @quickfeet7778
    @quickfeet7778 7 หลายเดือนก่อน

    interesting, i've been solving dp problems which only use recursion, so I assumed that dp generally applied only to recursive solutions, its good to see it used in a different way, thanks!

    • @nikoo28
      @nikoo28  6 หลายเดือนก่อน

      Every recursive problem has an iterative solution..and I usually prefer those..recursive code is super hard to read

  • @anarych1
    @anarych1 4 หลายเดือนก่อน +1

    Much better explanation than neetcode's one. Thank you!

    • @devprasad8767
      @devprasad8767 17 วันที่ผ่านมา

      Yes, but his code is more optimal in space complexity

  • @sudhanshukushwaha6351
    @sudhanshukushwaha6351 8 หลายเดือนก่อน +1

    masterpiece

  • @tanvirazad49
    @tanvirazad49 2 หลายเดือนก่อน

    thank you 🎉

  • @fagunraythatha5601
    @fagunraythatha5601 ปีที่แล้ว

    Hey buddy, I have been coding fgr a while, I use your videos as my revision. You are great brother, can you bring a series of hard algorithm with dynamic programming solution

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      for sure, i am planning to bring in all the hard problems as well. just need some time to build up the basics. I will start on those hard problems by the end of the year.

  • @rambhaktuchihaobito7987
    @rambhaktuchihaobito7987 10 หลายเดือนก่อน

    sir the way u teach...... is so good ❣❣

    • @nikoo28
      @nikoo28  10 หลายเดือนก่อน +1

      Thank you so much 😀

  • @subee128
    @subee128 6 หลายเดือนก่อน

    Thanks

  • @akshitjain2906
    @akshitjain2906 11 หลายเดือนก่อน +1

    legend bro legend

  • @VIJAYGUPTA-fc5hi
    @VIJAYGUPTA-fc5hi ปีที่แล้ว

    bro according to base case you provided what if arraylength ==0 and you are trying to access arr[0], is that not con concerning ??

  • @ganesang7217
    @ganesang7217 6 หลายเดือนก่อน +1

    😎 cool

  • @romanporter6331
    @romanporter6331 5 หลายเดือนก่อน

    спасибо, очень классно всё объясняешь. Я смотрел тебя с автоматическим кривым переводом через нейросеть и всё равно всё понял)

    • @nikoo28
      @nikoo28  4 หลายเดือนก่อน

      Я так рада, что смогла вам помочь.

  • @sukyuit
    @sukyuit 8 หลายเดือนก่อน +1

    max waali condition jo aapne btai woh hum pehli baar mein kaise sochein khud se ,for future problems jo developer solve krega

    • @nikoo28
      @nikoo28  7 หลายเดือนก่อน

      for dynamic programming, the more you practice, the more patterns you will start seeing. Most of the problems work on the same idea, the words are just twisted.
      One thing that often helps me is visualize where do I have to ultimately reach. Then start to build a backwards solution.

  • @beingstudent5571
    @beingstudent5571 12 วันที่ผ่านมา

    I think the way you explain is tabulation not memoization btw very excellent explanation .

    • @nikoo28
      @nikoo28  5 วันที่ผ่านมา

      tabulation is a way of memoization.

  • @candichiu7850
    @candichiu7850 ปีที่แล้ว +2

    The best on TH-cam!

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      So heartwarming to hear that :)

  • @AndyBnq
    @AndyBnq 28 วันที่ผ่านมา

    I swear, you are awfully underrated man, as opposed to Neetcode who are so overrated. No offence to Neetcode.
    Everytime I don't understand an explanation from Neetcode (which is almost always the case from problem 10 onwards in Neetcode Blind 75), I always come to you and you never let me down.

    • @nikoo28
      @nikoo28  27 วันที่ผ่านมา

      everyone has their own style of teaching, and everyone understands differently. Whatever helps you!! 😄
      Glad I am able to help you out. You can help by sharing and subscribing 😄

  • @aswanthnarayanan2942
    @aswanthnarayanan2942 ปีที่แล้ว +1

    Please make a video about Git

    • @nikoo28
      @nikoo28  ปีที่แล้ว +2

      that is a good suggestion. I will start preparing something on it. :)

  • @pranitagawas4806
    @pranitagawas4806 5 หลายเดือนก่อน

    Please provide the solution to the paint fence problem

    • @nikoo28
      @nikoo28  4 หลายเดือนก่อน

      i don't have access to the problem. Can you provide me an alternate link

  • @AmritSingh-du7pq
    @AmritSingh-du7pq ปีที่แล้ว

    Hello Bhaiya, Can you please make a video on Check If It Is a Good Array leetcode (1250).

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      i will add it to my queue and get a video out sometime...but to be honest..this is not a good problem to solve...doesn't actually test your logical or data structure skills.

  • @minnikeswarrao6185
    @minnikeswarrao6185 ปีที่แล้ว

    Sir any source to learn dynamic programming?

    • @nikoo28
      @nikoo28  ปีที่แล้ว +3

      Not to give you false hopes…but there is no source…the more you practice the more easily you will be able to identify patterns. Things will start to get a little comfortable day by day :)

  • @bhavindhobi79
    @bhavindhobi79 5 หลายเดือนก่อน

    how can i find the houses that i robbed??

    • @nikoo28
      @nikoo28  4 หลายเดือนก่อน

      start with the total loot at each index. with respect to the house you choose, store those results

  • @Ayush_kumar_1013
    @Ayush_kumar_1013 5 หลายเดือนก่อน

    fail test case 1,2,3,1

    • @nikoo28
      @nikoo28  5 หลายเดือนก่อน +1

      1,2,3,1 does give the answer as 4, which is correct. What answer do you expect ?

  • @pramanayagam
    @pramanayagam ปีที่แล้ว

    Bro what about input as [2,1,1,2]

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      The output should be 4. First house and the last house.

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      The above method will output as 4. My solution is based on the method and it gives a correct answer. Can you explain your thought process?

    • @pramanayagam
      @pramanayagam ปีที่แล้ว

      @@nikoo28 Ok bro

  • @prashanthshetty8337
    @prashanthshetty8337 4 หลายเดือนก่อน

    func rob(nums []int) int {
    if len(nums) == 1 {
    return nums[0]
    }
    if len(nums) == 2 {
    return max(nums[0], nums[1])
    }
    a := nums[0]
    b := max(nums[0], nums[1])
    for i := 2; i < len(nums); i++ {
    a, b = b, max(a + nums[i], b)
    }
    return b
    }