House Robber

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write rob(houses): houses lists the money in each house along a street, as whole numbers from 0 to 1,000. A thief can't take from two neighbouring houses, or the alarm goes off. Return the most money they can take. No houses gives 0. Leave houses unchanged. For example, rob([2, 7, 9, 3, 1]) is 12, from the 2, the 9 and the 1. The checks include 2,000 houses, so trying every choice of houses is too slow: work out the best total up to each house in turn.

Your code must pass

  • Finds the most money without two neighbours
  • Skips more than one house when that pays
  • Handles no houses, one or two
  • Is fast enough for 2,000 houses