House Robber

Maximum amount you can rob without robbing adjacent houses.

Pattern

Decision DP

This problem follows the Decision DP pattern, commonly found in the 1-D Dynamic Programming category. Recognizing this pattern is key to solving it efficiently in an interview setting.

Approach

How to Solve It

dp[i] = max(dp[i-1], dp[i-2] + nums[i]). Rob current or skip.

Key Insight

At each house, the optimal choice only depends on the last two results — this 'rolling' technique reduces O(n) space to O(1).

Step-by-step

  1. 1For each house, decide: rob it or skip it
  2. 2If you rob house i, you can't rob house i-1
  3. 3dp[i] = max(dp[i-1], dp[i-2] + nums[i])
  4. 4Optimize to two variables since you only need the last two values

Pseudocode

prev2, prev1 = 0, 0
for num in nums:
    prev2, prev1 = prev1, max(prev1, prev2 + num)
return prev1
Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)
More 1-D Dynamic Programming Problems

Master this pattern with YeetCode

Practice House Robber and similar 1-D Dynamic Programming problems with flashcards. Build pattern recognition through active recall.

Practice this problem