House Robber (LeetCode 198) | Full solution with diagrams | Easy explanation | Study Algorithms
ฝัง
- เผยแพร่เมื่อ 6 ก.ค. 2024
- 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
Top-notch explanation available on TH-cam, thanks!
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
finally i can sleep peacefully now...what an explaination. just wow... Thanks man!!!
Great to hear!
Amazing explanation. I was looking everywhere why this works and you manage to explain it in a way that clicked
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!
Best explanation on you tube, thank you
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 🔥.
Bro your explanation is just awesome!! u explained each step in detail
dayum...... awesome explanation brother. bows down. live long Nikhil.
Thank you so much! First time seeing someone explaining solution as good as NeetCode1
Excellent.. The best explanation on utube !
Very well explained. U have knack of teaching
The best explanation that i have ever found! thank u so much
Very to understand explanation, Loved it.
thank you for breaking this down! :)
Clearly explained, thankyou.
Great logic and great explanation! Expecting more videos.
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.
That is so amazing to hear 🤩
@@nikoo28 really awesome )
Incredible stuff !
Great video boss!
Leetcode is art and you're Picasso. Incredible explanation Nikhil!
Amazing explanation !!
ek no bhai
Thankyou sir!!
Great Explaination, beginners friendly.
No words. Simply wow!!!
your comment - "just looking like a wow"..thanks for the support.
This is the best I've seen anyone explain the problem. Thank you so much yaar.
always happy to have you as my audience :)
Great explanation thank you.
Subscribed , Nice Explaination
wow just a amazing , explaination great work
Your contents are great, highly appreciated , Please keep uploading more interesting problems.. Thanks
More to come!
Thank you very much for the well-explained video 👍
Great explanation, Thank you for sharing your knowledge.
My pleasure!
Thank you!!
Brother thank you so much 🥺❤ now I understand after you drawing those pictures
Excellent explanation 🤩
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 !!
thanks for the sub!!
it really helped bro!
Bro..U r tooo good.. The way u explained is awesome, super. Please keep it up...
omg my brain is physically hurting from this...
best explanation
Nice Explanation,
Amazing video
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!
Every recursive problem has an iterative solution..and I usually prefer those..recursive code is super hard to read
Much better explanation than neetcode's one. Thank you!
Yes, but his code is more optimal in space complexity
masterpiece
thank you 🎉
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
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.
sir the way u teach...... is so good ❣❣
Thank you so much 😀
Thanks
legend bro legend
bro according to base case you provided what if arraylength ==0 and you are trying to access arr[0], is that not con concerning ??
😎 cool
спасибо, очень классно всё объясняешь. Я смотрел тебя с автоматическим кривым переводом через нейросеть и всё равно всё понял)
Я так рада, что смогла вам помочь.
max waali condition jo aapne btai woh hum pehli baar mein kaise sochein khud se ,for future problems jo developer solve krega
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.
I think the way you explain is tabulation not memoization btw very excellent explanation .
tabulation is a way of memoization.
The best on TH-cam!
So heartwarming to hear that :)
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.
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 😄
Please make a video about Git
that is a good suggestion. I will start preparing something on it. :)
Please provide the solution to the paint fence problem
i don't have access to the problem. Can you provide me an alternate link
Hello Bhaiya, Can you please make a video on Check If It Is a Good Array leetcode (1250).
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.
Sir any source to learn dynamic programming?
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 :)
how can i find the houses that i robbed??
start with the total loot at each index. with respect to the house you choose, store those results
fail test case 1,2,3,1
1,2,3,1 does give the answer as 4, which is correct. What answer do you expect ?
Bro what about input as [2,1,1,2]
The output should be 4. First house and the last house.
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?
@@nikoo28 Ok bro
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
}