dsa · medium

House Robber II

Houses stand in a **circle**: the first and last houses are adjacent. nums[i] is the money in house i. You cannot rob two adjacent houses. Return the maximum you can rob without alerting the police.

Arguments

Example

[2,3,2]3 (the two 2s sit on adjacent ends of the circle).

[1,2,3,1]4 (take 1 and 3, skipping both neighbors of each).

[1,2,3]3.

Constraints

1 <= nums.length <= 100 0 <= nums[i] <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[2,3,2]

Expected:
3

Example 2

Input:
[1,2,3,1]

Expected:
4

Example 3

Input:
[1,2,3]

Expected:
3

Open in the Dojo editor