Summary
Keywords
Full Transcript
LeetCode 198 β House Robber is a classic Dynamic Programming problem: you want the maximum sum you can rob, but you cannot rob adjacent houses. In this video youβll learn: The DP idea and recurrence: dp[i] = max(dp[i-1], dp[i-2] + nums[i]) How to optimize to O(1) extra space Time complexity and edge cases Approach At each house, you have two choices: Skip it β keep the best so far (dp[i-1]) Rob it β add its money to the best up to i-2 (dp[i-2] + nums[i]) Complexity Time: O(n) Extra space: O(1) If you found this helpful, subscribe for more clean LeetCode explanations (DP, Greedy, Graphs). Playlist (LeetCode DP / Patterns): https://www.youtube.com/playlist?list=PLF0G-7pZcOza_jyAxwMpa5KnK3vST5smK LAN Academy: https://lanteam-solutions.com/ #LeetCode #DynamicProgramming #CodingInterview #CPlusPlus #leetcode #leetcodecoding #leetcodesolution #leetcodechallenge #faang #fang #computerscience #cs #codingtiktok #coding #codinglife #boostofhope #fyp #codinginterview #softwareengineer #swe #tech #foryou #python #learntocode #google #techtok #programming #algorithms #learntocode
