House Robber
Maximize non-adjacent values along one street.
Why does this pattern fit?
Restate the exact job
Maximize non-adjacent values along one street.
At each house choose between skipping it and taking it plus the best two back.
O(n) time · O(1) space
Greedily taking a locally large house can block a better combination.
How to solve House Robber
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 along one street.
Why Dynamic programming fits
At each house choose between skipping it and taking it plus the best two back.
State to maintain
Best through previous house and through the house before it.
Transition
Set current=max(previous, twoBack + value) and roll the pair forward.
Time and space
O(n) time · O(1) space
Counterexample to the tempting mistake
Greedily taking a locally large house can block a better combination.
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.