House Robber | LeetCode 198 | Google Coding Interview Tutorial

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • House Robber solution: LeetCode 198
    Code and written explanation: terriblewhiteboard.com/house-...
    Link to problem: leetcode.com/problems/house-r...
    Buy Me a Coffee: www.buymeacoffee.com/terrible...
    AFFILIATE LINKS
    If you're interested in learning algorithms, these are great resources.
    💻 40% off Tech Interview Pro: techinterviewpro.com/terriblew...
    ⌨️ 20% off CoderPro: coderpro.com/terriblewhiteboard
    💲 All coupons and discounts 💲
    terriblewhiteboard.com/coupon...
    House Robber | LeetCode 198 | Google Coding Interview
    #houserobber #leetcode #algorithms #terriblewhiteboard #codinginterview
    Click the time stamp to jump to different parts of the video.
    00:00 Title
    00:07 Problem readout
    01:03 Whiteboard solution
    04:09 Coding solution
    09:21 Result and outro

Komentáře • 56

  • @TerribleWhiteboard
    @TerribleWhiteboard  Před 4 lety +15

    If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!

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

      please make all variations of buying and selling stocks please !!

    • @275phuongvy
      @275phuongvy Před 3 lety

      can you make the video for Sort List ? #148 with the "BOTTOM UP MERGE SORT" solution? There are videos explaining this question. However, no one explain the bottom up merge sort with O(1) space complexity.

  • @thesuperiorman8342
    @thesuperiorman8342 Před 4 lety +23

    You are very gifted at teaching. I can't thank you enough.

  • @hyrdeshgangwar
    @hyrdeshgangwar Před 4 lety +4

    Brilliant! Whiteboard solution part was enough for me to get the logic. Thanks !

  • @rohitjaiswal4121
    @rohitjaiswal4121 Před 4 lety +11

    You explain very nicely. Please make a tutorial series on Dynamic Programming! Thanks for your efforts! :-)

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

    Your videos are great. Just a suggestion, it would be great to add Big O analysis and optimisations (e.g. don't need to store full dp array, can reduce space complexity from O(n) to O(1) by storing 2 variables instead.)

  • @leetann5341
    @leetann5341 Před 4 lety +18

    Love the way you explain things. Keep it up you are doing a great job and hope your channel grows.

  • @jwastken8814
    @jwastken8814 Před 3 lety

    I watched a bunch of videos on this problem and studied the discussion section on leet code. I was very confused until just now. You're a great teacher man. Thank you for your help.

  • @whatstwelveohnine
    @whatstwelveohnine Před 4 lety +11

    thank you so much

  • @rakshitnaidu5985
    @rakshitnaidu5985 Před 4 lety +8

    Great Explanation! Can't thank you enough for this!!

  • @souravmanjhi7238
    @souravmanjhi7238 Před 4 lety +12

    that was a wonderful explaination
    totally got the logic

  • @tkhalifeh
    @tkhalifeh Před 4 lety +11

    great job !

  • @adityatrivediii
    @adityatrivediii Před 4 lety +7

    Nicely explained ! Thanks

  • @bvhdv
    @bvhdv Před 2 lety

    This is the best explanation for this problem on CZcams. Thanks.

  • @shriramravishankar8800
    @shriramravishankar8800 Před 4 lety +3

    very clear explanation, thank you!

  • @szujanlin9820
    @szujanlin9820 Před 4 lety +5

    very well explained. Thanks for spending time for making this video

  • @albertszymanski7177
    @albertszymanski7177 Před 3 lety +1

    Excellent explanation. I spent nearly 2 hours trying to find an ultimate solution for every case but I gave up... Thanks to your explanation now I completely have a grasp of that problem. You're a brilliant teacher

  • @dammanhhieu
    @dammanhhieu Před 4 lety +12

    Very interesting 👍

  • @sylascoker1483
    @sylascoker1483 Před 3 lety +1

    You are the best man!!! I struggled so hard to understand but you've made it so cleart for me, thank you so much!! I implemented what you explained into my own code and it worked first time !!!

  • @namanvohra8262
    @namanvohra8262 Před 2 lety

    The best explanation so far, thank you for making this video!

  • @markzuckerbread1865
    @markzuckerbread1865 Před 3 lety +1

    very intuitive solution that helps a lot with other dp problems, thank you!

  • @duane1015
    @duane1015 Před 4 lety +6

    Is this the optimal solution? Space complexity could be reduced by only memo-izing the last max values (instead of memo-izing all of them)

    • @sunnilabeouf
      @sunnilabeouf Před 4 lety +4

      You're right, my space complexity shot up to 90% since now it's O(1) space. Here's my code:
      var rob = function(nums) {
      if(!nums || nums.length === 0) return 0;
      if(nums.length === 1) return nums[0]
      let prevMax = nums[0], currMax = Math.max(nums[0], nums[1]), tempMax
      for(let i = 2; i < nums.length; i++){
      tempMax = Math.max(prevMax + nums[i], currMax)
      prevMax = currMax
      currMax = tempMax
      }
      return currMax
      };

  • @bolarinwaowuogba3268
    @bolarinwaowuogba3268 Před 3 lety +1

    Thank you for explaining things so well

  • @275phuongvy
    @275phuongvy Před 3 lety +1

    great explanation. Thank you

  • @vivekgagrani8288
    @vivekgagrani8288 Před 3 lety

    Very good explanation sir

  • @antutucat8231
    @antutucat8231 Před rokem

    thanks

  • @cupofjava5480
    @cupofjava5480 Před rokem

    didn't pay much attention and thought you coded in java :)) , anyways very good teaching , I finally understood this 1d dp

  • @SoReaICru
    @SoReaICru Před 4 lety +7

    What app are you using to draw on these videos? It's like a whiteboard!

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 4 lety +8

      It’s just the standard Notes app on the iPad.

    • @krishna81m
      @krishna81m Před 4 lety +5

      @@TerribleWhiteboard What hardware is that? So, you just connect your IPad and write on screen? How was Mac able to split the drawing from IPad input and typing from Keyboard input at the same time?

    • @TerribleWhiteboard
      @TerribleWhiteboard  Před 4 lety +4

      I use the Apple Pencil to draw and a separate bluetooth external keyboard to type. They're both connected at the same time.

  • @ridhwaans
    @ridhwaans Před 3 lety

    wouldnt you get an out of bounds exception at the last number in the array loop?

  • @pranjalsingh1287
    @pranjalsingh1287 Před 3 lety +1

    Your voice feels like you are sad or cryring 😅

  • @allan1827
    @allan1827 Před 3 lety +1

    gg