Same as House robber, but the houses are in a circle: the first and last are neighbors.
Before you code
The first and last houses can't both be robbed, so at least one of them is skipped. Each case is a straight street.
Hints
- Answer = max(rob(nums[1:]), rob(nums[:-1])).
- One house is a special case: rob it.
Production & complexity notes
When solving House robber II on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in One-dimensional problems to reinforce the underlying pattern.
What it practices
Reducing a variant to the basic recurrence, from One-dimensional problems.