House Robber II

Your A3 solver worked on a street of houses. What happens when the street bends into a ring?

You've built a working House Robber. It scans a street of houses left to right, never robbing two neighbors, and returns the highest possible haul. Call it A3. It works.

Now a city planner calls with a question. The street is the same: five houses, same values, same rule — no two adjacent houses. But the planner bent the street into a ring. The last house and the first house are now neighbors.

On a linear street, houses 0 and 2 are at opposite ends. They've never met. But on a ring, they share a fence. The constraint that A3 was designed to enforce — "no two adjacent houses" — now has one more adjacency to consider. A3 never knew that pair existed.

Before you fix anything, consider the obvious shortcut that almost every engineer reaches for first.

— The naive idea:

"A3 works on linear arrays. A ring is just a linear array where you've forgotten which end is the start. So run A3 from every possible starting point and take the best result."

In other words: rotate the array, run A3 on each rotation, return the maximum. Seems reasonable. Try it below — see if it holds up.

Dead End: Try Rotating

Ring 232. Rotate it, run A3 on each rotation. The correct circular answer is 3. Does any rotation find it?