On this page
House Robber
Solving House Robber using 1D DP.
Problem
Max money without adjacent houses.
Pattern
This problem demonstrates the 1D DP pattern.
Approach
dp[i] = max(dp[i-1], dp[i-2] + nums[i]).
Solution
// Solution for House Robber
// Pattern: 1D DP
// O(n) time
Complexity
O(n) time
Best Practices
- Identify the pattern before coding — pattern recognition saves time
- Handle edge cases: empty input, single element, duplicates
- Use descriptive variable names even in timed interviews
- Test with the provided examples plus one custom case