No video

House Robber

  Рет қаралды 85,072

Kevin Naughton Jr.

Kevin Naughton Jr.

Күн бұрын

For business inquiries email partnerships@k2.codes My Desk Setup
Desk - bit.ly/3jfY195
Chair - amzn.to/2O9TM3r
Monitor - amzn.to/3rcSHGa
Webcam - amzn.to/2NUmwgi
Desktop - amzn.to/3tiySPL
Laptops - amzn.to/3aRoN3Z
iPad - amzn.to/2LlJzzJ
Keyboard - amzn.to/3jfbxdd
Mouse - amzn.to/36ElWtT
Wrist Rest - amzn.to/3trrHF4 (pls don't buy this)
Mouse Pad - amzn.to/2Myz2lt
Microphone - amzn.to/3atNyTA
Lamp - amzn.to/3jjfZYp
Headphones - amzn.to/3tvr0KU (new model)
Headphone Hook - amzn.to/3tr8uTC
Blue Light Glasses - amzn.to/3cDVUdK
Wireless Charger - amzn.to/39LY1uu
Keyboard cable - amzn.to/2O5p2R5
Mic arm - amzn.to/3cECZj8
Audio interface - amzn.to/36HdWIi
Cloudlifter - amzn.to/36VO6kf
Laptop dock - amzn.to/2O2DsBw
Motherboard - amzn.to/3rkiWuA
Solid state - amzn.to/3rk5vuo
CPU cooler - amzn.to/3tnwwPA
CableMod - amzn.to/3tqbtM8
CPU - amzn.to/3auG1ns
Power supply - amzn.to/3trsAxo
RAM - amzn.to/39JZcuf
Designing Data-Intensive Applications - amzn.to/2YK4ek1
Clean Code - amzn.to/3txqfB5
Meditations - amzn.to/3cDa4fi
SOCIAL
----------------------------------------------------------------------------------------------------------------
Support me on Patreon: / kevinnaughtonjr
Follow me on Twitter: / kevinnaughtonjr
Follow me on Instagram: / kevinnaughtonjr
Follow me on GitHub: github.com/kdn251
MUSIC
----------------------------------------------------------------------------------------------------------------
Blushes by Dj Quads
/ blushes
#coding #interviews #softwareengineering Discord: bit.ly/K2-discord

Пікірлер: 188
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
HOW DOPE IS MY SKI MASK
@jlecampana
@jlecampana 5 жыл бұрын
Love the Mask! and well, this one is a very nice and do-able DP problem. I was wondering if you could do #276 - Paint Fence? I couldn't do it for the life of me, and it's labelled as "Easy", so maybe I'm missing something and you can enlighten me. Thanks in Advance Kevin!
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
@@jlecampana Haha thanks and don't pay attention to the labels they're all subjective! I actually think I already have a video on that problem if you wanna check it out! And anytime, thank YOU for your support!!!
@jlecampana
@jlecampana 5 жыл бұрын
@@KevinNaughtonJr Oh I see it, you have done a video for LeetCode #256 - Paint House, How could I have missed it! I will see if I can actually solve the problem before watching your video. But I do think you should definitely check out #276, I could be wrong but I think it's Harder than most DP regulars. Have a nice day!
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
@@jlecampana I'll check it out thanks for the suggestion!!!
@PrathamMantri
@PrathamMantri 5 жыл бұрын
Thanks Kevin for the best explanation of DP problem. I could use this example as a start for solving DP problems.
@alperozdamar517
@alperozdamar517 4 жыл бұрын
I saw this question in real interview and be able to do it. Thank you Kevin. :)
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
No way that's amazing anytime :)
@aydasu
@aydasu 5 жыл бұрын
love the dp questions. i feel like i am starting to get it. thanks Kevin!
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
So so so so SO happy to hear that!
@bingo7137
@bingo7137 5 жыл бұрын
Purely Awesome! i'm kinda struggling with understanding the dynamic programming problems and this is the best explanation out here. Thank you once again for all your help.
@ahasunos5914
@ahasunos5914 2 жыл бұрын
Kevin, I've been following your tutorials since past couple of weeks. You don't need to doubt why do you have subscribers. Thank you for all the concepts.
@mkhanyisigamedze4807
@mkhanyisigamedze4807 4 жыл бұрын
This took me 2 hours and I'm reminded of how understanding key concepts is so efficient. Love your videos
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
thank you!
@SoferPeOZN
@SoferPeOZN 4 жыл бұрын
I think you got a dude moving in the background =)
@adityapaithon6499
@adityapaithon6499 4 жыл бұрын
yea creeped me out at 5:18
@OlsZn
@OlsZn 3 жыл бұрын
I love how you have the perfect camera window to block the previous tries of this question ;)
@jaidevsingh1009
@jaidevsingh1009 2 жыл бұрын
The clearest video on this problem, thank you!
@mohithguptakorangi1766
@mohithguptakorangi1766 3 жыл бұрын
now, that's how you explain "SHIT" in a "BEAUTIFUL" way
@hookedbeans
@hookedbeans 2 жыл бұрын
This is brilliant. Thank you!
@studyaccount794
@studyaccount794 2 жыл бұрын
We can improve this solution even further. We can use 3 variables instead of using a complete new array. Just like we do in fibonacci. Code- public int rob(int[] nums) { int loot1 = 0; int loot2 = 0; for (int i = 0; i
@jaysaxena185
@jaysaxena185 3 жыл бұрын
Excellent Solution Kevin, cleared the concept of dp, through this explanation. Too Good, short, and on-point.
@ayanagrawal
@ayanagrawal 3 жыл бұрын
Update : This is in medium now.
@priyanshmathur3010
@priyanshmathur3010 2 жыл бұрын
Bro, all those memes and explanations were lit!! Great Video :D
@selinadu1579
@selinadu1579 5 жыл бұрын
Awesome solution. Plz plz keep doing these tutorials. Love them!
@svddwd
@svddwd 3 жыл бұрын
Very nice explanation and approach . Thank you.
@user-bc5wf2qq2r
@user-bc5wf2qq2r 10 ай бұрын
very intuitive, thanks!
@wheresthebeach0138
@wheresthebeach0138 4 жыл бұрын
Hey Kevin, thank you for this! IMO, it's your best video to date :) I think you took the perfect amount of time to explain the logic before diving into the code; really clicked for me. Thank you!
@loirobin
@loirobin 5 жыл бұрын
@Kevin your solution explanation is simple and crystal clear, thanks a lot
@wakita
@wakita 5 жыл бұрын
Thanks for doing the dynamic programming problems, I've been trying various difficulty ones for a while, and one of the things thats helped me the most has been watching your Leetcode videos, along with BackToBack SWE and Tushar Roy. I did something pretty similar to you in my Javascript solution, but did it in place, modifying the original input array. I think this could also be done in constant space and not modifying the input by using a variable to represent max up to i - 1 and max up to i - 2. Javascript solution ===== var rob = function(nums) { if (nums.length === 0) return 0; if (nums.length === 1) return nums[0]; for (let i=1; i
@datajunkie3427
@datajunkie3427 4 жыл бұрын
The question starts with: You are a professional robber planning to rob houses along a street... That's a good start
@Slumpicus
@Slumpicus 5 жыл бұрын
You're killing it, dude. Keep it up!
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
Thanks Grayson I really appreciate it and don't worry I'm not going anywhere! New video is uploading now so get ready to check it out. Thanks so much for your support!
@ichdiegross
@ichdiegross 4 жыл бұрын
You did a great job at explaining the concept properly!
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
Thanks Pranav!
@jagrutijamba9093
@jagrutijamba9093 3 жыл бұрын
Hi Kevin, nice try. But your alogrithm would not return the correct answer in the following case : [2,1,3,4]. The answer should be 2+4 = 6. As both the locations are non-consecutive and lead to max loot. Hence, I tried solving this problem with recursion instead.
@killersdeat0
@killersdeat0 5 жыл бұрын
Great intuition! A lot of people only keep 2 numbers (value if you robbed the house vs value if you didn't) and alternate saving the variables but I think that building the dp table is a lot more intuitive. We can also simplify the space complexity of the solution to be O(1) once we see the concept of building the table out in a real interview scenario
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
Thanks and definitely very good point!!!
@theanonymousfoodie8906
@theanonymousfoodie8906 3 жыл бұрын
this question was asked in my interview and I'm not able to solve that, now it looks very simple to me. Dammmmm!!!
@ENGCS_JaiSaxena
@ENGCS_JaiSaxena 2 жыл бұрын
that is unbelivable , how are u able to solve so easily dude.great work.
@AmolGautam
@AmolGautam 2 жыл бұрын
Thank you for the explaination.
@georgiossamaras5063
@georgiossamaras5063 3 жыл бұрын
You don't need the if statement for the 2 houses case. Nice explanation, thanks!
@AliMehrpour-Volcano
@AliMehrpour-Volcano 5 жыл бұрын
Crystal clear and neat explanation, good job as always 👍
@SaumyaSharma007
@SaumyaSharma007 3 жыл бұрын
Thank you so much Sir 🌟 Awesome explanation out there. Huge love and Respect from India 🌟🤗
@hitec1691
@hitec1691 5 жыл бұрын
Nicely explained. Thank you
@DhruvPatel-kg5ut
@DhruvPatel-kg5ut 5 жыл бұрын
Awesome bro. This is the 3rd video I saw for this problem and now I actually could figure out the solution. Thanks.
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
Anytime Dhruv happy to hear the video was helpful :)
@alammahtab08
@alammahtab08 4 жыл бұрын
Very well explained. Below is the code in case if someone wants to try out. Both, with the dp[] array and without dp array. With dp[] array : O(n) Space class Solution { public int rob(int[] nums) { if(nums == null || nums.length == 0) return 0; if(nums.length == 1) return nums[0]; if(nums.length == 2) return Math.max(nums[0], nums[1]); int[] dp = new int[nums.length]; dp[0] = nums[0]; dp[1] = Math.max(nums[0], nums[1]); for(int i = 2; i < nums.length; i++) { dp[i] = Math.max(nums[i] + dp[i-2], dp[i-1]); } return dp[nums.length-1]; } } Without dp[] array : O(1) Space class Solution { public int rob(int[] nums) { if(nums == null || nums.length == 0) return 0; if(nums.length == 1) return nums[0]; if(nums.length == 2) return Math.max(nums[0], nums[1]); int maxBeforeTwoHouse = nums[0]; int maxBeforeOneHouse = Math.max(nums[0], nums[1]); int maxAtI = Math.max(nums[0], nums[1]); for(int i = 2; i < nums.length; i++) { maxAtI = Math.max(maxBeforeTwoHouse+ nums[i] , maxBeforeOneHouse); maxBeforeTwoHouse = maxBeforeOneHouse; maxBeforeOneHouse = maxAtI; } return maxAtI; } } github.com/eMahtab/house-robber
@crimsoncad3230
@crimsoncad3230 4 жыл бұрын
This is the 1st dp problem for which I paused the video and got the DP logic on my own. This should be the 1st video to watch when you start learning DP. Initially I thought of 2 independent loops that calculates the sum of all odd and even plce elements, then take the max out of it. But this seems more optimized and useful for new concept.
@vaichegodas
@vaichegodas 4 жыл бұрын
you cant use 2 for loops to solve the problem
@shredchic
@shredchic 4 жыл бұрын
I tried the odd/even thing as well first, but it will miss the max in some cases. Consider [8, 1, 9, 2, 5, 20] With checking odd vs. even, the max would be 23. However, the best robbery is 37. :)
@tirthjayswal9895
@tirthjayswal9895 4 жыл бұрын
Really Good Explentation
@mp0157
@mp0157 5 жыл бұрын
Thank you Kevin!! Good and simplified explanation! :) This helped!
@economicriskcapitalmodelpr9849
@economicriskcapitalmodelpr9849 4 жыл бұрын
This is my first visit to this channel and it's really impressive.Thanks for sharing your knowledge !! I am going to watch at least one video everyday.
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
Anytime and thanks for the support!
@vaishnavipamulapati9920
@vaishnavipamulapati9920 2 жыл бұрын
i was struggling with this problem for a day 😔 but your explanation was very intuitive! thank you!
@manulscode
@manulscode 4 жыл бұрын
The robber is already sleeping in the background.:D
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
hahahah
@hyonsoo79
@hyonsoo79 4 жыл бұрын
Very easy to understand. Thank you!
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
Anytime Kevin!
@objectivesworld31
@objectivesworld31 4 жыл бұрын
Hi Kevin nice explanation of dp. but we are sequentially processing so there is no need of dp array. if we change logic like this int first = nums[0]; int second = Math.max(nums[0],nums[1]); int ans = 0; for(int i=2; i
@AshishSingh-dn8wb
@AshishSingh-dn8wb 4 жыл бұрын
We actually don't need to check if nums.length==2 in the beginning. We are taking care of that in the loop itself. Anyway, loved the explanation. Love your videos man!
@PrashantNigam
@PrashantNigam 5 жыл бұрын
An improvement over this solution. Same as for Nth Fibonacci number. Without DP array. // T/S: O(n)/O(1) public int rob(int[] nums) { if (nums.length == 0) return 0; if (nums.length == 1) return nums[0]; int twoBack = nums[0]; int oneBack = Math.max(nums[0], nums[1]); int curr = b; for (int i = 2; i < nums.length; i++) { curr = Math.max(nums[i] + twoBack, oneBack); twoBack = oneBack; oneBack = curr; } return curr; }
@marlegagaming1274
@marlegagaming1274 3 жыл бұрын
man, you made it look so easy...
@kairu86
@kairu86 4 жыл бұрын
Very helpful. Thanks!
@anurag1908
@anurag1908 2 жыл бұрын
Just WOW!!!
@ayeshaadhikari6123
@ayeshaadhikari6123 2 жыл бұрын
Thanks a tonne Kevin!
@rajdipdas9413
@rajdipdas9413 2 жыл бұрын
this problem can be solved by including first number from first index or excluding first number from first index and continue for the next indices.
@ridhwaans
@ridhwaans 3 жыл бұрын
the confusing part is how the dp array carries over the largest sum without overlapping sums and maintaining non adjacency
@renetchi
@renetchi 3 жыл бұрын
Why do you have subscribers? lollll because you're awesome!
@humblecoder9119
@humblecoder9119 5 жыл бұрын
Super explanation. Good to understand DP like this.
@ChocolateMilkCultLeader
@ChocolateMilkCultLeader 4 жыл бұрын
Bro this one was genius. Hats off for a great solution
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
devansh thanks dude
@ecea044gauravgogoi2
@ecea044gauravgogoi2 3 жыл бұрын
so nicely explained
@ishikanagar3236
@ishikanagar3236 3 жыл бұрын
loved it!
@mp0157
@mp0157 5 жыл бұрын
Very well explained intution! :) Thanks, this was of immense help!
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
Mihir Phatak thanks Mihir! Happy to hear the video was helpful :)
@vashi1989
@vashi1989 4 жыл бұрын
simple and nice explanation.. i dont think we need an extra array.. i tried with the provided nums arrays and it worked.
@user-cl9el4iu4s
@user-cl9el4iu4s 4 жыл бұрын
Thank you! Really explained my struggles.
@saulgoodman980
@saulgoodman980 4 жыл бұрын
My Python solution: def rob(nums): dp = [0, 0] # having 0s instead of nums[0] and max(nums[:2]) handles cases where len(nums) is 0 or 1 or 2 for num in nums: dp.append(max(dp[-1], num + dp[-2])) return dp[-1]
@yv6358
@yv6358 4 жыл бұрын
Oh! Hey when did you start programming?
@saulgoodman980
@saulgoodman980 4 жыл бұрын
@@yv6358 It's been 5 years since I started (in school), but I've become serious only from the last 1.5 years
@yv6358
@yv6358 4 жыл бұрын
@@saulgoodman980 What happened to your career in law?
@saulgoodman980
@saulgoodman980 4 жыл бұрын
@@yv6358 Oh xD Well, you'll know in BCS S06 ;)
@yv6358
@yv6358 4 жыл бұрын
@@saulgoodman980 waiting for it
@DanOhCaptainDaniel
@DanOhCaptainDaniel 5 жыл бұрын
Every time you say "hopefully that's not too confusing" makes me start to assume the explanation you are about to make is going to be confusing haha. I really enjoy your videos, but I think the way you explain for some reason, it does not click for me. Maybe leetcode is still a little too complex for my programming level... I may just have to spend more time looking at the problems myself. Either way, thank you for having the solutions. I hope you answer every leetcode problem so we all have a reference solution for all the leetcode problems! Thank you again.
@shubhammishra1225
@shubhammishra1225 2 жыл бұрын
Now this question become Leetcode medium. Still Dope mask and video.
@mayankdixit401
@mayankdixit401 4 жыл бұрын
My greatest achievement was that I was able to find that it is a dp problem. Now I can relate to the solution, thanks :)
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
Nice!!!
@masoomraza5155
@masoomraza5155 2 жыл бұрын
Thank you you are a life saver
@lewisnt_
@lewisnt_ 2 жыл бұрын
god tier thumbnail
@sandeep_khangar
@sandeep_khangar 2 жыл бұрын
Awesome explanation
@MyVegeta
@MyVegeta 4 жыл бұрын
yes i have the same reaction when i understand DB
@tomiwaolasoko7291
@tomiwaolasoko7291 4 жыл бұрын
Thanks, great solution!
@shubhoch2368
@shubhoch2368 2 жыл бұрын
Hey, first of all I really like your videos the way you approach a dp problem makes it so soo simple. Thank you! Can you please make a video on Leetcode problem number 152, I just want to know how you will approach that problem in case you have time to do so!
@Matt-xq6ow
@Matt-xq6ow 2 жыл бұрын
I'm confused by the solution, can someone explain? I'm stuck understanding: dp[i] = Math.max(nums[i] + dp[i-2], dp[i-1]); Doesn't this mean we possibly have the chance of selecting an adjacent house instead of every other house?
@lazycoder1910
@lazycoder1910 3 жыл бұрын
The explanation was really amazing
@heeseung5
@heeseung5 5 жыл бұрын
Nice mask haha made me laugh
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
Haha thanks happy to hear it :)
@peterdinklage3856
@peterdinklage3856 4 жыл бұрын
Awesome explanation mate!! thanks a lot!!
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
Swapnil Shukla anytime happy it was helpful!
@CoolnesXcore
@CoolnesXcore 3 жыл бұрын
If you want to save some extra space, we can just add the elements to the nums array. :)
@wenzhongtan1358
@wenzhongtan1358 3 жыл бұрын
Great explanation! Just a question, we could probably shorten the last line to from dp[nums.length - 1] to dp[-1], right?
@ashleywilkonson386
@ashleywilkonson386 3 жыл бұрын
This isn't the optimal, constant space solution.
@Plopcorn02
@Plopcorn02 2 жыл бұрын
Kevin how many years of experienced have you had as a coder for using Java. Im intrested.
@tavleenkaur6941
@tavleenkaur6941 4 жыл бұрын
Hey Kevin, your videos are very insightful and helping alot of people like me prepping up for the interviews. One thing I’d like to point in this question is that Is DP even necessary here? The first intuition that hit my mind when I read the question was to take the sum of the entire array (sum) and sum of all the alternate elements beginning from 0 (i.e. element at index 0 ,2, 4, till n-1 or n-2), lets call it X. The answer should be max(X , sum-X). Please let me know if there is something wrong in this approach ?
@darkcaper703
@darkcaper703 4 жыл бұрын
[2,1,1,2] -> u need to rob 1st and last to get maximum
@ridhwaans
@ridhwaans 3 жыл бұрын
this is a sliding window technique
@oneautumnleaf47
@oneautumnleaf47 3 жыл бұрын
Any referrence for dp? Where can I learn that? They don't teach it at school. lol
@seal0118
@seal0118 3 жыл бұрын
how do results not overlap, is there proof to this?
@GURUYATHI
@GURUYATHI 5 жыл бұрын
Great Solution..!
@arpitverma8060
@arpitverma8060 4 жыл бұрын
Awesome explanation of this question by a bottom up approach ..Can you explain it by a Top down ?
@HarinathSrinivas
@HarinathSrinivas 4 жыл бұрын
Hey, the question you have solved is, "maximum sum in an array such that no 2 elements are adjacent". I was asked this question in an interview, tell me how to solve this. Given an array and an int value K, find Maximum sum of numbers, such that no 2 elements are adjacent and sum not greater than K.
@rjose705
@rjose705 4 жыл бұрын
damm
@rjose705
@rjose705 4 жыл бұрын
Okay, im not sure if its this simple or not, but wouldn't the question devolve into checking whether the sum of the even numbered indices is greater than the odd? the only possible combos are all the even numbered indices and odd numbered indices. But i don' think its that easy
@Vikasslytherine
@Vikasslytherine 4 жыл бұрын
How to identify if a certain problem's going to need dynamic problem to solve?
@user-gk3iq3lm7t
@user-gk3iq3lm7t 3 жыл бұрын
I notice that you didn't use length + 1 for dp array this time, but for some other questions like number of coins and decoded ways all used length + 1 may I ask why this is otherwise?
@yicai7
@yicai7 4 жыл бұрын
Omg I really like ur bgm at the beginning!!
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
thanks Yi!
@FrankLi92
@FrankLi92 5 жыл бұрын
Do we need to create a new array? Can we overwrite the current array for O(1) space?
@cocoarecords
@cocoarecords 5 жыл бұрын
thanks wow well explained and ery clear
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
Thanks so much happy to hear the explanation made sense :)
@ronaldabellano5643
@ronaldabellano5643 5 жыл бұрын
I like the music youre using!
@KevinNaughtonJr
@KevinNaughtonJr 5 жыл бұрын
ronald abellano thanks Ronald!!!
@brijeshtiwari1357
@brijeshtiwari1357 3 жыл бұрын
Can we sort this array first and then start adding non adjacent elements from n-1 ?
@christianrascioni8178
@christianrascioni8178 3 жыл бұрын
If you sort the array first, you lose the original order and don't know what houses are adjacent anymore
@mdk124
@mdk124 3 жыл бұрын
This was asked by Bytedance as well, but I haven't seen the question before the interview :') . Hackerrank calls it boxes game instead.
@mostlyharmless161
@mostlyharmless161 3 жыл бұрын
Epic thumbnail btw xD
@PROTECHRAHUL
@PROTECHRAHUL 2 жыл бұрын
Thumbnail 🤣
@sunittechjourney9640
@sunittechjourney9640 3 жыл бұрын
What did you do on line 13? int[] dp = new int[nums.length] ? What is that?
@lazycoder1910
@lazycoder1910 3 жыл бұрын
It's java 😂
@naveensmart87
@naveensmart87 4 жыл бұрын
awsome buddy !!!
@KevinNaughtonJr
@KevinNaughtonJr 4 жыл бұрын
thanks Naveen!
@daipayanhati2347
@daipayanhati2347 4 жыл бұрын
strange that the the recursive overlaping subsets gives a heap overflow error; int Max_Rob(vector& nums,int i,int * dp){ if(i>=nums.size()){ return 0; } if(dp[i]!=0){ return dp[i]; } return dp[i] = max(Max_Rob(nums,i+2,dp)+nums[i],Max_Rob(nums,i+3,dp)+nums[i+1]); } int rob(vector& nums) { int dp[120] = {0}; return Max_Rob(nums,0,dp); }
@JitendraSingh-rw9bt
@JitendraSingh-rw9bt 4 жыл бұрын
Without extra space. class Solution { public int rob(int[] nums) { int dp1 =0, dp2= 0, max = 0; for(int i = 0; i < nums.length; i++) { max = Math.max(nums[i]+dp1, dp2); dp1 = dp2; dp2 = max; } return dp2; } }
@cam5862
@cam5862 4 жыл бұрын
1. great understandable DP explanation 2. love your freeze frame gold esp at 1:22 (that's some field theory sh*t I had to learn for cryptography 🤣) thanks for your helping me prep for my Google interview next week!
@SoferPeOZN
@SoferPeOZN 4 жыл бұрын
So, i guess you're a googleer now? :) Hope yes
@cam5862
@cam5862 4 жыл бұрын
@@SoferPeOZN unfortunately not :( I'm an Amazonian tho!
Word Search
8:46
Kevin Naughton Jr.
Рет қаралды 139 М.
The HARSH Reality of Working in Big Tech
8:42
Kevin Naughton Jr.
Рет қаралды 21 М.
这三姐弟太会藏了!#小丑#天使#路飞#家庭#搞笑
00:24
家庭搞笑日记
Рет қаралды 23 МЛН
Joker can't swim!#joker #shorts
00:46
Untitled Joker
Рет қаралды 40 МЛН
Bony Just Wants To Take A Shower #animation
00:10
GREEN MAX
Рет қаралды 7 МЛН
House Robber - Leetcode 198 - Dynamic Programming (Python)
13:15
Next Closest Time
8:47
Kevin Naughton Jr.
Рет қаралды 31 М.
An Entire Computer Science Degree in 11 Minutes
11:13
Kevin Naughton Jr.
Рет қаралды 774 М.
Richard Feynman: Can Machines Think?
18:27
Lex Clips
Рет қаралды 1,5 МЛН
WashU Professors Read Their Rate My Professor Reviews
11:12
Student Life Newspaper
Рет қаралды 913 М.
Getting Promoted WON'T Make You Happy...
6:21
Kevin Naughton Jr.
Рет қаралды 5 М.
Coin Change
10:16
Kevin Naughton Jr.
Рет қаралды 153 М.
How Robbing Houses Can Make You Better At Dynamic Programming
18:04
Kantan Coding
Рет қаралды 4,1 М.
The SAT Question Everyone Got Wrong
18:25
Veritasium
Рет қаралды 12 МЛН
My last startup coding video
10:48
jedcal
Рет қаралды 122 М.
这三姐弟太会藏了!#小丑#天使#路飞#家庭#搞笑
00:24
家庭搞笑日记
Рет қаралды 23 МЛН