Skip to content

House Robber II

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

This time the houses stand in a circle, so the first and last houses are neighbours too. As before, nums[i] is the number of coins in house i, and you may never collect from two adjacent houses. Return the most coins you can collect.

nums = [2, 3, 2]     →  3   (houses 0 and 2 touch, so take house 1)
nums = [1, 2, 3, 1]  →  4   (houses 0 and 2)
nums = [1, 2, 3]     →  3

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000