Skip to content
Onsite

House Robber II

MediumP2Coding

nums[i] is the money in house i. The houses stand in a circle, so house 0 is next to house n - 1. You cannot rob two adjacent houses. Return the maximum amount you can rob.

With one house, you may rob it.

Example 1

Input
nums = [2,3,2]
Output
3
Why
Houses 0 and 2 are neighbours in the circle, so the best is house 1 alone.

Example 2

Input
nums = [1,2,3,1]
Output
4

Example 3

Input
nums = [5]
Output
5

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000

Hints

Run checks the 3 visible tests, Submit all 10.