House Robber II
Choose houses on a circle without choosing adjacent houses, including the first and last pair. Return the greatest sum of their nonnegative values.
Example 1
nums = [4,1,1,4]5Explanation
The first and last 4 are adjacent on the circle; combine either with the opposite interior 1 for 5.
Example 2
nums = [8]8Explanation
A singleton allows taking its only house for 8.
Example 3
nums = [2,3,2]3Explanation
The endpoint 2s are adjacent, so taking the middle 3 is better.
Constraints
- 1 <= len(nums) <= 100
- Values are 0..1000
Function contract
robArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[4,1,1,4]