Skip to content

House Robber

MediumDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.

Houses along a street hold nums[i] coins each. You may collect from any houses you like, but never from two neighbours, because adjacent alarms are linked. Return the most coins you can collect.

nums = [1, 2, 3, 1]     →  4    (houses 0 and 2)
nums = [2, 7, 9, 3, 1]  →  12   (houses 0, 2 and 4)
nums = [2, 1, 1, 2]     →  4    (houses 0 and 3)

An empty street gives 0.

Constraints

  • 0 <= nums.length <= 100
  • 0 <= nums[i] <= 400