House Robber II
You are given a row of houses arranged in a circle. Each house contains some amount of money.
You want to collect as much money as possible, but there is one rule:
- you cannot rob two houses that are next to each other
- because the houses are in a circle, the first house and the last house are also next to each other
Return the largest amount of money you can rob without robbing any adjacent houses.
Examples
Input: [2,3,2]
Output: 3
Input: [1,2,3,1]
Output: 4
Hints
Handle the circular nature by considering two cases: exclude first house or exclude last house.
Apply the linear house robber solution to both ranges.
Return the maximum of the two cases.
Related Problems
House Robber II
You are given a row of houses arranged in a circle. Each house contains some amount of money.