CodeOath
← All problems

House Robber II

Medium
dynamic-programming

Same rules as House Robber, but now the houses are arranged in a circle — the first and last houses are adjacent. Return the maximum amount of money you can rob without robbing two adjacent houses.

Example:

Input: nums = [2,3,2]
Output: 3
Explanation: Robbing house 1 (money = 2) and house 3 (money = 2) is not allowed because they are adjacent. The best is to rob house 2 (money = 3).

Constraints:

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