Same as House Robber but houses are arranged in a circle. First and last are adjacent. Return max money without alerting.
In a circle, we can't rob both first and last. So the optimal is either: best excluding last, or best excluding first. These two linear subproblems cover all valid solutions.
Trying every subset of houses that are not adjacent is exponential. The circle is the only new difficulty compared with House Robber 1.
The first and the last house can never both be robbed. So solve two straight line problems. One skips the last house, and the other skips the first house. For each line, use the House Robber rule: the best up to house i is the larger of skipping it, or robbing it plus the best up to i minus 2. The answer is the larger of the two results.
Break a circle by solving two lines, each excluding one end. Then reuse the linear solution.
Run the animation above on your own input, or watch the 1:43 video explanation of House Robber II with a dry run and Java code.