Dynamic Programming pattern
House Robber
Houses are arranged in a row, each holding some money, but robbing two adjacent houses triggers the alarm. Return the maximum amount you can rob without alerting the police. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 198
- Medium
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Dynamic ProgrammingLeetCode 198
Medium
From the first idea to the best one
- 01 Brute force · recursion O(2ⁿ)O(n) space
- 02 Optimized · tabulation O(n)O(1) space
What you will learn
- How to read House Robber and spot the dynamic programming pattern in it
- Brute force · recursion: O(2ⁿ) time, O(n) space
- Optimized · tabulation: O(n) time, O(1) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Dynamic Programming
See House Robber run, step by step
Sign in and this page opens on the animation, with all 18 Dynamic Programming problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.