LeetCode 198. House Robber (Algorithm Explained)

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2025

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

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

    yo you should have kept the robber mask while doing the question

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

    This in old and I don't know if you ever read your subscribers comments, but I have to tell you one amazing thing about you. You have an incredible talent to explain complicated things in a very simple way. Yet, there is an extra impressive feature on your methodology of explaining things. You explain them really fast. Normally, one expect to make it more difficult to follow. But it is the other way around with your videos. You explains things very fast *AND* make them easy to understand. I don't think you even realize this. It is a bit antagonist, how can you explain it so well and so fast? But, man it works great. Thanks for posting these solutions with fast and easy explanations.

  • @ryan.aquino
    @ryan.aquino 4 ปีที่แล้ว +24

    Explaining the template for dynamic programming did helped me.

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

    Hi Nick, can you create a path or a map for beginners to follow which algorithm /data structure should they learn first and what problems should they do first.

  • @oscaropdyou
    @oscaropdyou 4 ปีที่แล้ว +4

    Thanks for the video. Here is slightly modified/improvised code:
    int dp[] = new int[nums.length];
    dp[0] = nums[0]; dp[1] = Math.max(dp[0], nums[1]);
    for(int i=2; i

    • @aba0101
      @aba0101 3 ปีที่แล้ว

      However, this solution will cause ArrayIndexOutofBounds unless you put another if(nums.length == 1) return dp[1].

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

    You lost me from 8:47 to 9:52 and sadly that the most important part :(

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

    I find it easier to solve the problems after understanding a task via a decision tree. However after building out the decision tree and seeing that max_money_stealable is dependent on amount of money the robber has stolen so far, it became pretty difficult to move forward with.
    For those who have MASTERED DP, this is probably an easy problem. For those that are still looking for easily digestible/understandable material on this topic called "Dynamic Programming", it's not easy.

  • @firefly2008god
    @firefly2008god 4 ปีที่แล้ว +7

    Hello Nick. You explained this very nicely. Could you please make a playlist exclusively for Dynamic Programming problems? That would be extremely helpful. Thanks.

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

    I think apart from Fibonacci, this is the first time I truly understood a DP problem, even though its considered Easy. Thank you Nick, You explain really really well!

  • @nevikgnehz368
    @nevikgnehz368 3 ปีที่แล้ว

    11:00 There should be 4 elements. On line 5 you declared nums.length + 1 so [1,2] should be of array size of 3 and since array is zero based it goes from 0th index to 3rd which is total of 4 spaces.

  • @kittwwang
    @kittwwang 4 ปีที่แล้ว +4

    The template is really helpful! Very clear explanation again!

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

    you really have a gift for this. i've been struggling to understand this when all i had to do was watch a couple of your videos to get it. THANK YOUUUUU

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

    Great explanation. I like how you made clear what the template was for a dp problem.

  • @BigBobEdyS
    @BigBobEdyS 2 ปีที่แล้ว

    Finally i understood this problem! Thank you... Also the fact that you used an array instead of a variable to show the progression of the maxvalue helped to understand

  • @andreandrews6237
    @andreandrews6237 4 ปีที่แล้ว +4

    Could have used Kadane's Algorithm to do this in O(1) space :) with the same runtime
    if (nums.Length == 0) return 0;
    if (nums.Length < 2 ) return nums[0];
    int ans = Math.Max(nums[0], nums[1]);
    int a = nums[0];
    for (int i = 2; i < nums.Length; i++)
    {
    var temp = Math.Max(ans, a + nums[i]);
    a = ans;
    ans = temp;
    }
    return ans;
    ^^ for reference if anyone was wondering (C#) implementation

  • @prepat2133
    @prepat2133 2 ปีที่แล้ว

    dude i'm literally only applying for SWE internship as a college junior and most of my OAs had dynamic programming. I'm not even joking.

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

    Hey Nick,
    Just curious why we need an array "dp" when we already know that last element is going to be the result. Can we simply have 2 variables one to store prev-result and another for fina-result and do the same thing. Help me if I am missing anything...
    func rob(_ nums: [Int]) -> Int {
    guard nums.count > 0 else { return 0 }
    var prevResult: Int = 0
    var result: Int = nums[0]
    for i in 1..

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

    Did you ever end up doing that video on the main types of problems and how to spot them?

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

    Nick I dont usually comment but this was a really good video. I’ve seen videos before about dynamic programming but they all made it seemed like this really advanced topic for no reason. When its just storing values in an array. Please make more videos just explaining each category of problems in simple terms this video was really helpful. 👍

  • @sophia0282
    @sophia0282 2 ปีที่แล้ว

    Can you please explain why the templet always set as int dp[] = new int [nums.length + 1]? What does mean to add 1? I still don't understand.

  • @curesnow6493
    @curesnow6493 3 ปีที่แล้ว

    Hello Nick,
    I wish I am very good at solving coding problems without looking at the solutions. What are your advice?

  • @ujjvalsharma5055
    @ujjvalsharma5055 4 ปีที่แล้ว

    Hey nick if you did a video on dynamic programming where you are explains types of dynamic programming question. Please send the link. I would like to watch.

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

    there is some problems with the subtitles.....

  • @ramkrishnasingh56
    @ramkrishnasingh56 5 ปีที่แล้ว

    Hey Nick I would like to solve all the problem you taught , is there any path in which I should do the questions ?

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

    what's up with the camera quality nick.. when you used your macbook the camera quality was better

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

    It can be one of two options. 1+3+..... +till the end or 2+4 +....+till the end since they can't be negative

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

      Not necessarily. If two very large numbers are 5 indexes away from one another, they can be combined e.g.:
      1, 100, 1, 1, 1, 1, 100, 1
      Your method would return a max of 103 where the maximum is actually 201.

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

    You are a good sarcastic comedian

  • @ashishkarn9283
    @ashishkarn9283 2 ปีที่แล้ว

    How about this,
    public int rob(int[] nums) {
    if(nums.length>1){
    nums[1]=Math.max(nums[0],nums[1]);
    }
    for (int i = 2; i < nums.length; i++) {
    nums[i]=Math.max(nums[i]+nums[i-2],nums[i-1]);
    }
    return nums[nums.length-1];
    }

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

    Great understandable explanation, As we need only last two values, we can just maintain two variables and get the answer..that way space complexity would be O(1)..
    Edit.: For those who missed it in video.!

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

      mentioned in the video

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

      @@NickWhite guess i skipped over that part..😅

  • @Jeremy-dh6ks
    @Jeremy-dh6ks 5 ปีที่แล้ว

    Happy Holidays Nick. I saw in your previous videos that you used a mac, and now you are using windows. Any particular reason why you switched?

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

      I bought a gaming PC and it’s pretty good for live streaming so I’m just messing around with it atm Happy holidays to you as well!

  • @ManishKumar-rz9ub
    @ManishKumar-rz9ub 4 ปีที่แล้ว +1

    This is not memoization. This is tabulation, a bottom up approach.

    • @sujaysreedhar8313
      @sujaysreedhar8313 4 ปีที่แล้ว

      Yes, thanks for saying that... I pretty much broke my head thinking of how it would be a memoization

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

    I still didn't see how the code covered that edge case of jumping two houses and grab the third, even though your code passed the edge use cases...
    EDIT: Did a table test an got it:
    dp [0, 40, 40, 44, 50]
    40, 2, 4, 10

  • @Cruzylife
    @Cruzylife 2 ปีที่แล้ว

    wheres the study guide

  • @ibrahimshaikh3642
    @ibrahimshaikh3642 4 ปีที่แล้ว

    Good one, can you make video for dp

  • @coleeastman4910
    @coleeastman4910 4 วันที่ผ่านมา

    They changed it from easy to medium, I wonder why

  • @Jeremy-dh6ks
    @Jeremy-dh6ks 5 ปีที่แล้ว

    0:45 WideHard

  • @MIDNightPT4
    @MIDNightPT4 3 ปีที่แล้ว

    "Not your morals" lmaoooooooo

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

    That thumbnail though😈😈

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

    Great explanation

  • @Rahulyadav-lv7dh
    @Rahulyadav-lv7dh 3 ปีที่แล้ว

    immaculate explanation

  • @iamkhanhnguyen
    @iamkhanhnguyen 4 ปีที่แล้ว

    Great explanation. You save my day bro

  • @thecarrotdude
    @thecarrotdude 2 ปีที่แล้ว

    Think again buster!

  • @firecracker-i2h
    @firecracker-i2h 3 ปีที่แล้ว

    every time he says its the easiest problem i m like that isnt true that's why i am watching your video

  • @anuragv400
    @anuragv400 4 ปีที่แล้ว

    Thnx man ! It helped a lot :)

  • @YNA64
    @YNA64 4 ปีที่แล้ว

    "Hello guys it's Nick White chushdskfjdksjfksjfks INFORMATION ksjdfkdj House Robber ". hHhahaha jk

  • @nknidhi321
    @nknidhi321 3 ปีที่แล้ว

    Thanks Nick!!

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

    Great job

  • @adithyaas2324
    @adithyaas2324 2 ปีที่แล้ว

    man you are very fast!

  • @rogerchou7762
    @rogerchou7762 3 ปีที่แล้ว

    Dude you are awesome!

  • @tanmaydeshpande2458
    @tanmaydeshpande2458 3 ปีที่แล้ว

    Think again buster! LMAO!

  • @Stephen_luk
    @Stephen_luk 2 ปีที่แล้ว

    It helps , thanks.

  • @aumrudhlalkumartj1948
    @aumrudhlalkumartj1948 2 ปีที่แล้ว

    Thanks

  • @AdityaSahu95
    @AdityaSahu95 3 ปีที่แล้ว

    Upvoting just because of that thumbnail xD

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

    love you man

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

    Well now it is medium :)

  • @QuickstickD
    @QuickstickD 3 ปีที่แล้ว

    You lost me from 00:00 - 13:25 😁 I’m joking I’m just watching because I want to learn.

  • @akanshkumar2876
    @akanshkumar2876 4 ปีที่แล้ว

    u deserve a like for that mask

  • @joineynguyen
    @joineynguyen 4 ปีที่แล้ว

    You cracked me up lol.

  • @vikramreddy7586
    @vikramreddy7586 4 ปีที่แล้ว

    The rap king!

  • @jonathontucker
    @jonathontucker 5 ปีที่แล้ว

    This is helpful even if you aren't using java

  • @LoneWolf-th6gn
    @LoneWolf-th6gn 2 ปีที่แล้ว

    Boom!😆

  • @ahmedfattah5879
    @ahmedfattah5879 5 ปีที่แล้ว

    17

  • @amansinhparmar3336
    @amansinhparmar3336 4 ปีที่แล้ว

    Boom

  • @AnonymousBoy_764
    @AnonymousBoy_764 2 ปีที่แล้ว

    This is now under Medium category

  • @tkokflux6322
    @tkokflux6322 2 ปีที่แล้ว

    bro is in 8k