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

  Рет қаралды 22,503

Nikhil Lohia

Nikhil Lohia

Күн бұрын

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 ай бұрын
Top-notch explanation available on KZbin, thanks!
@zeltrax00
@zeltrax00 8 ай бұрын
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 ай бұрын
finally i can sleep peacefully now...what an explaination. just wow... Thanks man!!!
@nikoo28
@nikoo28 4 ай бұрын
Great to hear!
@varoonsb
@varoonsb Күн бұрын
Thank you so much! First time seeing someone explaining solution as good as NeetCode1
@carl1809
@carl1809 5 ай бұрын
Amazing explanation. I was looking everywhere why this works and you manage to explain it in a way that clicked
@papercut._.
@papercut._. 6 ай бұрын
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!
@surendhar.v4952
@surendhar.v4952 Жыл бұрын
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 🔥.
@siddharthmehta4223
@siddharthmehta4223 11 ай бұрын
dayum...... awesome explanation brother. bows down. live long Nikhil.
@hari7110
@hari7110 5 ай бұрын
Bro your explanation is just awesome!! u explained each step in detail
@010101dddm
@010101dddm Жыл бұрын
Best explanation on you tube, thank you
@TalesOfGranny
@TalesOfGranny 6 ай бұрын
Very well explained. U have knack of teaching
@lucianpetriuc7373
@lucianpetriuc7373 4 ай бұрын
Leetcode is art and you're Picasso. Incredible explanation Nikhil!
@qR7pK9sJ2t
@qR7pK9sJ2t 6 ай бұрын
Excellent.. The best explanation on utube !
@daffapradana8557
@daffapradana8557 Жыл бұрын
The best explanation that i have ever found! thank u so much
@rajeshpaithari7320
@rajeshpaithari7320 2 ай бұрын
Great logic and great explanation! Expecting more videos.
@gojosatoru988
@gojosatoru988 Жыл бұрын
Very to understand explanation, Loved it.
@DilshadAhmad-pc1tm
@DilshadAhmad-pc1tm 5 ай бұрын
Bro..U r tooo good.. The way u explained is awesome, super. Please keep it up...
@kamalasowmya7120
@kamalasowmya7120 5 ай бұрын
thank you for breaking this down! :)
@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!!
@rishichansauria3658
@rishichansauria3658 Жыл бұрын
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 Жыл бұрын
That is so amazing to hear 🤩
@serg1778
@serg1778 10 ай бұрын
@@nikoo28 really awesome )
@puneetchhabra2578
@puneetchhabra2578 Жыл бұрын
Thankyou sir!! Great Explaination, beginners friendly.
@user-fk2xu3fh5r
@user-fk2xu3fh5r 7 ай бұрын
Brother thank you so much 🥺❤ now I understand after you drawing those pictures
@yomamasofat413
@yomamasofat413 24 күн бұрын
omg my brain is physically hurting from this...
@badrinarayanans355
@badrinarayanans355 6 ай бұрын
Clearly explained, thankyou.
@makethemostOfwhatYouGot
@makethemostOfwhatYouGot 2 ай бұрын
Incredible stuff !
@khyatikakkar9259
@khyatikakkar9259 Ай бұрын
Amazing explanation !!
@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 :)
@ramswrooppatidar7599
@ramswrooppatidar7599 5 ай бұрын
wow just a amazing , explaination great work
@RohitSharma-mg3np
@RohitSharma-mg3np 5 ай бұрын
Subscribed , Nice Explaination
@jus3472
@jus3472 5 ай бұрын
Great explanation thank you.
@YashRekha594
@YashRekha594 7 ай бұрын
Thank you very much for the well-explained video 👍
@abhisheknandann
@abhisheknandann Жыл бұрын
Great video boss!
@jishnus1526
@jishnus1526 8 ай бұрын
Excellent explanation 🤩
@anonymous-ze5fg
@anonymous-ze5fg Жыл бұрын
Your contents are great, highly appreciated , Please keep uploading more interesting problems.. Thanks
@nikoo28
@nikoo28 Жыл бұрын
More to come!
@adityamaurya554
@adityamaurya554 3 ай бұрын
ek no bhai
@mukeshperiyasamy3364
@mukeshperiyasamy3364 Жыл бұрын
Great explanation, Thank you for sharing your knowledge.
@nikoo28
@nikoo28 Жыл бұрын
My pleasure!
@504rishukumar4
@504rishukumar4 5 ай бұрын
Nice Explanation,
@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 ??
@unknownman1
@unknownman1 7 ай бұрын
No words. Simply wow!!!
@nikoo28
@nikoo28 6 ай бұрын
your comment - "just looking like a wow"..thanks for the support.
@kunalkheeva
@kunalkheeva 10 ай бұрын
it really helped bro!
@rogerthat7190
@rogerthat7190 11 ай бұрын
Thank you!!
@jayprajapati9
@jayprajapati9 Жыл бұрын
best explanation
@mock1112
@mock1112 Жыл бұрын
Amazing video
@tanvirazad49
@tanvirazad49 2 ай бұрын
thank you 🎉
@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 ай бұрын
Much better explanation than neetcode's one. Thank you!
@devprasad8767
@devprasad8767 15 күн бұрын
Yes, but his code is more optimal in space complexity
@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 Жыл бұрын
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.
@sudhanshukushwaha6351
@sudhanshukushwaha6351 8 ай бұрын
masterpiece
@rambhaktuchihaobito7987
@rambhaktuchihaobito7987 10 ай бұрын
sir the way u teach...... is so good ❣❣
@nikoo28
@nikoo28 10 ай бұрын
Thank you so much 😀
@subee128
@subee128 6 ай бұрын
Thanks
@AndyBnq
@AndyBnq 26 күн бұрын
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 25 күн бұрын
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 😄
@sukyuit
@sukyuit 8 ай бұрын
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.
@akshitjain2906
@akshitjain2906 11 ай бұрын
legend bro legend
@ganesang7217
@ganesang7217 6 ай бұрын
😎 cool
@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.
@romanporter6331
@romanporter6331 5 ай бұрын
спасибо, очень классно всё объясняешь. Я смотрел тебя с автоматическим кривым переводом через нейросеть и всё равно всё понял)
@nikoo28
@nikoo28 4 ай бұрын
Я так рада, что смогла вам помочь.
@minnikeswarrao6185
@minnikeswarrao6185 Жыл бұрын
Sir any source to learn dynamic programming?
@nikoo28
@nikoo28 Жыл бұрын
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 :)
@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
@beingstudent5571
@beingstudent5571 10 күн бұрын
I think the way you explain is tabulation not memoization btw very excellent explanation .
@nikoo28
@nikoo28 3 күн бұрын
tabulation is a way of memoization.
@aswanthnarayanan2942
@aswanthnarayanan2942 Жыл бұрын
Please make a video about Git
@nikoo28
@nikoo28 Жыл бұрын
that is a good suggestion. I will start preparing something on it. :)
@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
@pramanayagam
@pramanayagam Жыл бұрын
Bro what about input as [2,1,1,2]
@nikoo28
@nikoo28 Жыл бұрын
The output should be 4. First house and the last house.
@nikoo28
@nikoo28 Жыл бұрын
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
@Ayush_kumar_1013
@Ayush_kumar_1013 5 ай бұрын
fail test case 1,2,3,1
@nikoo28
@nikoo28 5 ай бұрын
1,2,3,1 does give the answer as 4, which is correct. What answer do you expect ?
@prashanthshetty8337
@prashanthshetty8337 3 ай бұрын
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 }
@candichiu7850
@candichiu7850 Жыл бұрын
The best on KZbin!
@nikoo28
@nikoo28 Жыл бұрын
So heartwarming to hear that :)
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 44 МЛН
Must-have gadget for every toilet! 🤩 #gadget
00:27
GiGaZoom
Рет қаралды 12 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Зачем нужны указатели в C++?
8:14
Dima
Рет қаралды 1,9 М.
How Robbing Houses Can Make You Better At Dynamic Programming
18:04
Kantan Coding
Рет қаралды 3,7 М.
House Robber | Recursion | Memo | Bottom Up | Leetcode 198
29:51
codestorywithMIK
Рет қаралды 9 М.
House Robber -  Leetcode 198 - Python Dynamic Programming
10:35
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 44 МЛН