Most Cash Around a Circular Street
Problem statement
Houses stand around a circular street. money[i] is the cash in house i, and house i is next to houses i - 1 and i + 1. Because the street is a circle, the first house (index 0) and the last house (index money.length - 1) are also next to each other.
You may collect the cash from any set of houses, but never from two houses that are next to each other. Return the largest total you can collect.
If there is only one house, it has no neighbors, so you can take it.
Function
maxLootCircle(money: int[]) → intExamples
Example 1
money = [7,2,3,8,1,6]return = 16Taking indexes 0, 3 and 5 would give 7 + 8 + 6 = 21, but on a circle index 5 is next to index 0, so that plan is not allowed. The best legal plan takes indexes 1, 3 and 5: 2 + 8 + 6 = 16. Plans that keep index 0 reach at most 7 + 8 = 15.
Example 2
money = [9,2,2,9]return = 11The two 9s sit at the ends of the list, and on a circle the ends are neighbors, so you cannot take both. The best is one 9 plus the 2 that is not next to it: 9 + 2 = 11.
Example 3
money = [6]return = 6With one house there are no neighbors, so take it.
Constraints
1 <= money.length <= 4000 <= money[i] <= 1000