#198
Medium
Dynamic Programming

House Robber

Choose non-adjacent houses to maximize stolen money.

DP

Pattern fit

This is the cleanest take-or-skip DP because each position only has two meaningful choices: rob it and skip the previous, or skip it and keep the previous best.

Key observation

The state only needs the best answer up to the previous position and the position before that.

Target complexity

O(n) / O(1)

How to break down the solution cleanly

1

This is the cleanest take-or-skip DP because each position only has two meaningful choices: rob it and skip the previous, or skip it and keep the previous best.

2

The state only needs the best answer up to the previous position and the position before that.

3

Name the state in plain language.

4

List the decisions that can transition into the state.

Reference implementation

Python
# Generic pattern template
# 1D DP
dp = [0] * (n + 1)
dp[0] = base
for i in range(1, n + 1):
    dp[i] = transition(dp, i)

# 2D DP
dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, m + 1):
        dp[i][j] = transition(dp, i, j)

Common pitfalls

warning

Confusing current value with global answer so far.

warning

Not handling short arrays separately.

Common follow-ups

How does House Robber II change with circular adjacency?

Can you explain the rolling-state version?

Continue with related problems

Build repeatable depth inside the Dynamic Programming cluster before moving on.

view_weekBack to the pattern page
LeetCode 198. House Robber Guide | Interview AiBox