House Robber II
Maximize non-adjacent values arranged in a circle.
Why does this pattern fit?
Restate the exact job
Maximize non-adjacent values arranged in a circle.
First and last cannot both be used, so split into two linear cases.
O(n) time · O(1) space
Running the linear recurrence across the full circle permits both endpoints.
How to solve House Robber II
The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.
What the question asks
Maximize non-adjacent values arranged in a circle.
Why Dynamic programming fits
First and last cannot both be used, so split into two linear cases.
State to maintain
Linear robber state for ranges excluding first or excluding last.
Transition
Solve both ranges and take the larger; handle one house separately.
Time and space
O(n) time · O(1) space
Counterexample to the tempting mistake
Running the linear recurrence across the full circle permits both endpoints.
Prove it again tomorrow
Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.