You are a professional thief planning to rob houses along a circular street. The houses are arranged in a circle, meaning the first dwelling and the last dwelling are directly adjacent to each other. An array nums represents the money stashed in each house, all amounts non‑negative. A security system connects neighbouring houses, so you cannot rob two houses that sit next to each other in the circle.
Determine the maximum total money you can steal without triggering the alarm.
Example 1
Input: nums = [4,1,2,7]
Output: 8
Explanation: Because the first and last houses are adjacent, taking both 4 and 7 is forbidden. The best choice is to rob houses at index 1 and index 3 for a total of 1 + 7 = 8.
nums = [4, 1, 2, 7]8
We have 4 houses in a circle. The first house (index 0) has $4, and the last house (index 3) has $7. They are adjacent because the street is circular.
Example 2
Input: nums = [5,3,5]
Output: 5
Explanation: The two houses holding 5 are neighbours in the circular layout, so only one of them can be robbed.
Example 3
Input: nums = [2,9,4,3,8]
Output: 17
Explanation: Houses at index 1 and index 4 are not adjacent, so taking 9 + 8 = 17 is valid and maximal.
Example 4
Input: nums = [6]
Output: 6
Constraints:
1 <= nums.length <= 1000 <= nums[i] <= 1000nums = [4, 1, 2, 7]8
We have 4 houses in a circle. The first house (index 0) has $4, and the last house (index 3) has $7. They are adjacent because the street is circular.