Explanation
House Robber is a Medium interview problem tagged [Array, Dynamic Programming]. The winning approach is typically **DP**.
#198
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. The only constraint stopping you from robbing each of them is that adjacent houses have security systems connected, and it will automatically contact the police if two adjacent houses are broken into on the same night.
Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
Example 1
Input: nums = [1,2,3,1]
Output: 4
Rob house 1 (1) and then house 3 (3).
Example 2
Input: nums = [2,7,9,3,1]
Output: 12
Rob houses 1, 3, and 5: 2+9+1 = 12.
House Robber is a Medium interview problem tagged [Array, Dynamic Programming]. The winning approach is typically **DP**.
Overlapping subproblems are solved once and reused.
Define dp state → write transition → fill base cases → iterate in dependency order.
Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.
Time: O(n)
Space: O(n)
Before coding, restate the problem, name the pattern (DP), and write the invariant or DP state in one sentence.
Got it?
Mark #198 House Robber as understood when the pattern clicks.