House Robber
best(i) = max(best(i-1), best(i-2) + value(i)). Take or skip.
DP in One Row: House robber
House 1 is worth 7. Skip it: dp[0] = 2. Take it: dp[-1] + 7 = 7. Best: 7, take.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Taught by the same lesson
DP in One Row covers these too, in the same run.