House Robber
best(i) = max(best(i-1), best(i-2) + value(i)); take or skip.
Decision · step 3 of 7DP in One Row: House robber
House 1 is worth 7. Skip it: dp[0] = 2. Take it: dp[-1] + 7 = 7. Best: 7, take.
What you will see
Each cell chooses between two arrows; the chosen one is emphasized.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(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.