medium1-D Dynamic ProgrammingLinkedInAmazon
Burglar Row Planner
A cat burglar picks a non-adjacent subset of houses on one street to maximize total loot without triggering alarms between neighbors.
Given an array of non-negative integers representing money in each house, return the max you can rob without taking from two adjacent houses.
Choose approach
2
07
1?
2?
3?
4i
1/5
Narrationstep 1 of 5
Base dp[0], dp[1].
Variables
How to think about it
- Two choices at each house.
- Rolling two scalars gives O(1) space.
Edge cases to catch in interview
- Empty -> 0.
- One house -> that value.
Examples
Example 1
4{"nums":[1,2,3,1]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed