AlgoScope

House Robber

Algorithmintermediate1D Dynamic Programming

best(i) = max(best(i-1), best(i-2) + value(i)); take or skip.

Decision · step 3 of 7DP in One Row: House robber
2071923314i

House 1 is worth 7. Skip it: dp[0] = 2. Take it: dp[-1] + 7 = 7. Best: 7, take.

Open in the player →or start at step 3

What you will see

Each cell chooses between two arrows; the chosen one is emphasized.

How dp in one row works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(1)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Table cells announce their state and value; each step announces which cells were read and the value written.

Reduced motion: Dependency arrows appear statically and the cell value crossfades.

Before this

Taught by the same lesson

DP in One Row covers these too, in the same run.