LeetCode 198. House Robber (Algorithm Explained)

  Рет қаралды 54,010

Nick White

Nick White

4 жыл бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow Me on X/Twitter - x.com/nickwhitereal
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 69
@djBC10000
@djBC10000 4 жыл бұрын
yo you should have kept the robber mask while doing the question
@guitarvoicing
@guitarvoicing Жыл бұрын
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 жыл бұрын
Explaining the template for dynamic programming did helped me.
@quangvo4563
@quangvo4563 4 жыл бұрын
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.
@kittwwang
@kittwwang 3 жыл бұрын
The template is really helpful! Very clear explanation again!
@emmanuelonwumah915
@emmanuelonwumah915 4 жыл бұрын
You lost me from 8:47 to 9:52 and sadly that the most important part :(
@Edysamaha
@Edysamaha 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
@firefly2008god
@firefly2008god 4 жыл бұрын
Hello Nick. You explained this very nicely. Could you please make a playlist exclusively for Dynamic Programming problems? That would be extremely helpful. Thanks.
@PR1V1LE6ED
@PR1V1LE6ED Жыл бұрын
Great explanation. I like how you made clear what the template was for a dp problem.
@oscaropdyou
@oscaropdyou 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 2 жыл бұрын
However, this solution will cause ArrayIndexOutofBounds unless you put another if(nums.length == 1) return dp[1].
@LoXatoR94
@LoXatoR94 3 жыл бұрын
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!
@chelseakatsidzira7153
@chelseakatsidzira7153 4 жыл бұрын
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
@nevikgnehz368
@nevikgnehz368 2 жыл бұрын
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.
@ramkrishnasingh56
@ramkrishnasingh56 4 жыл бұрын
Hey Nick I would like to solve all the problem you taught , is there any path in which I should do the questions ?
@iamkhanhnguyen
@iamkhanhnguyen 3 жыл бұрын
Great explanation. You save my day bro
@dalgonacovfefe
@dalgonacovfefe 4 жыл бұрын
Did you ever end up doing that video on the main types of problems and how to spot them?
@curesnow6493
@curesnow6493 2 жыл бұрын
Hello Nick, I wish I am very good at solving coding problems without looking at the solutions. What are your advice?
@anuragv400
@anuragv400 3 жыл бұрын
Thnx man ! It helped a lot :)
@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.
@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.
@rupaldesai7098
@rupaldesai7098 4 жыл бұрын
You are a good sarcastic comedian
@nknidhi321
@nknidhi321 3 жыл бұрын
Thanks Nick!!
@ahmedz7414
@ahmedz7414 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. 👍
@dera_ng
@dera_ng Жыл бұрын
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.
@Jeremy-dh6ks
@Jeremy-dh6ks 4 жыл бұрын
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 4 жыл бұрын
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!
@HeyTiGBeats
@HeyTiGBeats Жыл бұрын
Great explanation
@ahmadtibi7744
@ahmadtibi7744 4 жыл бұрын
what's up with the camera quality nick.. when you used your macbook the camera quality was better
@rogerchou7762
@rogerchou7762 3 жыл бұрын
Dude you are awesome!
@rathan235
@rathan235 Жыл бұрын
Great job
@Rahulyadav-lv7dh
@Rahulyadav-lv7dh 2 жыл бұрын
immaculate explanation
@ibrahimshaikh3642
@ibrahimshaikh3642 4 жыл бұрын
Good one, can you make video for dp
@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..
@Stephen_luk
@Stephen_luk 2 жыл бұрын
It helps , thanks.
@prakad97
@prakad97 4 жыл бұрын
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 4 жыл бұрын
mentioned in the video
@prakad97
@prakad97 4 жыл бұрын
@@NickWhite guess i skipped over that part..😅
@andreandrews6237
@andreandrews6237 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
@JohnWickea
@JohnWickea 6 ай бұрын
love you man
@aumrudhlalkumartj1948
@aumrudhlalkumartj1948 2 жыл бұрын
Thanks
@MIDNightPT4
@MIDNightPT4 2 жыл бұрын
"Not your morals" lmaoooooooo
@prepat2133
@prepat2133 Жыл бұрын
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.
@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]; }
@yuvrajdarekar3494
@yuvrajdarekar3494 3 жыл бұрын
That thumbnail though😈😈
@LiLzViEtzThuGGn
@LiLzViEtzThuGGn 3 жыл бұрын
You cracked me up lol.
@thecarrotdude
@thecarrotdude Жыл бұрын
Think again buster!
@viniciusfilenga4730
@viniciusfilenga4730 9 ай бұрын
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
@adithyaas2324
@adithyaas2324 2 жыл бұрын
man you are very fast!
@Jeremy-dh6ks
@Jeremy-dh6ks 4 жыл бұрын
0:45 WideHard
@vikramreddy7586
@vikramreddy7586 4 жыл бұрын
The rap king!
@Cruzylife
@Cruzylife Жыл бұрын
wheres the study guide
@AdityaSahu95
@AdityaSahu95 3 жыл бұрын
Upvoting just because of that thumbnail xD
@tanmaydeshpande2458
@tanmaydeshpande2458 3 жыл бұрын
Think again buster! LMAO!
@Mentalist06
@Mentalist06 11 ай бұрын
Well now it is medium :)
@shohanur_rifat
@shohanur_rifat 4 жыл бұрын
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 жыл бұрын
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.
@akanshkumar2876
@akanshkumar2876 3 жыл бұрын
u deserve a like for that mask
@nischayrawat682
@nischayrawat682 2 жыл бұрын
every time he says its the easiest problem i m like that isnt true that's why i am watching your video
@ahmedfattah5879
@ahmedfattah5879 4 жыл бұрын
17
@LoneWolf-th6gn
@LoneWolf-th6gn Жыл бұрын
Boom!😆
@amansinhparmar3336
@amansinhparmar3336 4 жыл бұрын
Boom
@ManishKumar-rz9ub
@ManishKumar-rz9ub 3 жыл бұрын
This is not memoization. This is tabulation, a bottom up approach.
@sujaysreedhar8313
@sujaysreedhar8313 3 жыл бұрын
Yes, thanks for saying that... I pretty much broke my head thinking of how it would be a memoization
@YNA64
@YNA64 4 жыл бұрын
"Hello guys it's Nick White chushdskfjdksjfksjfks INFORMATION ksjdfkdj House Robber ". hHhahaha jk
@jonathontucker
@jonathontucker 4 жыл бұрын
This is helpful even if you aren't using java
@QuickstickD
@QuickstickD 2 жыл бұрын
You lost me from 00:00 - 13:25 😁 I’m joking I’m just watching because I want to learn.
@fettuccine794
@fettuccine794 Жыл бұрын
This is now under Medium category
@tkokflux6322
@tkokflux6322 Жыл бұрын
bro is in 8k
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1 МЛН
Git Tutorial For Dummies
19:25
Nick White
Рет қаралды 1 МЛН
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 7 МЛН
Comfortable 🤣 #comedy #funny
00:34
Micky Makeover
Рет қаралды 10 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 44 МЛН
House Robber II - Dynamic Programming - Leetcode 213
10:40
NeetCode
Рет қаралды 118 М.
I Got Rejected (again)
9:43
Nick White
Рет қаралды 203 М.
LeetCode 22. Generate Parentheses
12:39
Nick White
Рет қаралды 81 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 406 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 158 М.
LeetCode 55. Jump Game (Algorithm Explained)
10:06
Nick White
Рет қаралды 77 М.
Maximum Product Subarray - Dynamic Programming - Leetcode 152
15:31
Как бесплатно замутить iphone 15 pro max
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
Bluetooth connected successfully 💯💯
0:16
Blue ice Comedy
Рет қаралды 2 МЛН
Ускоряем ваш TV🚀
0:44
ARTEM_CHIBA
Рет қаралды 418 М.
Nokia 3310 top
0:20
YT 𝒯𝒾𝓂𝓉𝒾𝓀
Рет қаралды 4,4 МЛН