AlgoViz

House robber

medium 18 min

Pick houses along a street to maximise the money taken, never two neighbours.

Where it shows up

The same pattern appears across everyday software.

  • Shift and slot scheduling with rest periods

    Choosing which days to work, or which time slots to book, when every chosen slot needs a gap after it is exactly this problem. The pay or value per slot is nums, and the rest rule is the alarm between neighbours.

  • Spacing out ads and promotions

    Feeds and video players often forbid two ads back to back. Picking which gaps to fill to maximise expected revenue, with no two adjacent, is a maximum-weight selection on a line, solved by the same recurrence.

  • Tasks with a cooldown

    Jobs that stress the same machine, muscle group or API quota often need a cooldown slot after each run. Picking the most valuable set of runs under a one-slot cooldown is house robber; longer cooldowns look back further than two.

  • Maximum-weight independent set on paths and trees

    Choosing nodes so that no two chosen nodes are connected is hard on general graphs, but on a path it is house robber and on a tree it is House Robber III. Network design and facility placement use these special cases, for example placing transmitters so that neighbours do not interfere.

  • Picking a menu or buffet plate

    The original app's buffet line: dishes in a row, and you cannot carry two that sit next to each other. It is the same problem with food, and a handy way to explain DP to someone new.