House Robber II
medium1-D Dynamic Programmingcircular array — run house robber on two rangesB75Solve on LeetCode#213
Same setup as House Robber — nums[i] is the cash in house i and robbing two adjacent houses trips the alarm — except now the houses form a circle: the first and last houses are neighbors of each other too.
Return the maximum cash you can collect without robbing any two adjacent houses on the circle.
Constraints: 1 <= nums.length <= 100 and 0 <= nums[i] <= 1000.
Examples
- Input:
- nums = [2, 3, 2]
- Output:
- 3
You cannot rob both house 0 and house 2 (they are adjacent on the circle), so the best is house 1 alone: 3.
- Input:
- nums = [1, 2, 3, 1]
- Output:
- 4
Rob houses 0 and 2 for 1 + 3 = 4. They are not adjacent even on the circle.
- Input:
- nums = [5]
- Output:
- 5
One house is its own circle; rob it.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.