House Robber
Choose non-adjacent houses to maximize stolen money.
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
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.
The state only needs the best answer up to the previous position and the position before that.
Name the state in plain language.
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
Confusing current value with global answer so far.
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.