Each house holds some money; robbing two adjacent houses triggers an alarm. Return the most you can rob.
Before you code
For each house, compare the best without it and the best with it, which rules out its left neighbor.
Hints
dp[i] = max(dp[i-1], dp[i-2] + nums[i]).- Handle one and two houses as base cases.
- Reduce to two variables: O(1) space.
Production & complexity notes
When solving House robber on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in One-dimensional problems to reinforce the underlying pattern.
What it practices
The take-or-skip recurrence, from One-dimensional problems.