Houses in a circle
A thief plans one night on a street of houses built in a circle. money[i] is the cash in house i. Each house is next to the houses on either side of it, and because the street closes into a circle, the last house is also next to house 0. Robbing two houses that stand next to each other sets off an alarm, so the thief never robs two neighbors.
Return the most cash the thief can collect. A street with a single house has no neighbors to worry about.
money = [4, 1, 2, 6]Output7Houses 1 and 3: 1 + 6 = 7. Houses 0 and 3 would give 10, but they are neighbors around the circle.
money = [6, 4, 5, 2]Output11Houses 0 and 2: 6 + 5. The circle does not get in the way here.
money = [5, 5, 5, 5, 5]Output10On a straight street, houses 0, 2 and 4 would give 15, but houses 0 and 4 are neighbors now. At most two of five houses in a circle can be robbed.
1 ≤ len(money) ≤ 100
0 ≤ money[i] ≤ 500
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.