PROBLEM 48 OF 75

House Robber

Maximize non-adjacent values along one street.

PATTERNDynamic programmingState is the smallest information needed to finish.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Maximize non-adjacent values along one street.

WHY THIS FITS

At each house choose between skipping it and taking it plus the best two back.

COMPLEXITY

O(n) time · O(1) space

COMMON FAILURE

Greedily taking a locally large house can block a better combination.

THE REASONING, IN ONE PLACE

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.

Open blank recall ↗