Gamified challenge · Dynamic programming
houses[i] is the loot inside house i along a street. You may rob any set of houses, but never two next to each other: neighbours share an alarm.
Write maxLoot(houses) (Python: max_loot) that returns the most loot you can take. For [2, 7, 9, 3, 1] the answer is 12 (houses 0, 2 and 4). For [2, 1, 1, 2] it is 4: rob houses 0 and 3.
An empty street gives 0. Loot values are between 0 and 400 and there are at most 100 houses.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google