Notice Period

Burglar on a Ring

medium

Same burglar, new neighborhood: the houses form a closed ring around a cul-de-sac, so the first and last houses are also neighbors. Adjacent houses still share an alarm.

Given loot around the ring, return the maximum haul with no two adjacent houses robbed — remembering that loot[0] and loot[-1] are adjacent now.

Example 1
in loot = [2, 3, 2]
out 3
Houses 0 and 2 are neighbors on the ring; best is house 1 alone.
Example 2
in loot = [1, 2, 3, 1]
out 4
Rob houses 0 and 2 — they aren't adjacent even on the ring.
Constraints
  • · 1 <= len(loot) <= 1000
  • · 0 <= loot[i] <= 10^4
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.