Description

Houses are arranged in a circle. Adjacent houses have security systems connected. Given an array representing money at each house, return the maximum amount you can rob without alerting the police.

Examples

Input:nums = [2,3,2]
Output:3
Explanation:

Rob house 2 (money = 3). Can't rob house 1 and 3 as they're adjacent in circle.

Input:nums = [5,1,3,9]
Output:10
Explanation:

Since houses are in a circle, robbing house 1 excludes house 5. The optimal selection of non-adjacent houses in a circular arrangement yields a maximum of 14.

Input:nums = [4]
Output:4
Explanation:

With only one house, it is possible to rob it without any adjacency concerns. The circular constraint doesn't matter with a single house.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!