House Robber II
Real-world version: Restocking a Ring of KiosksThe statement here is our own: the same inputs, outputs and technique.
Vending kiosks stand in a circle around a plaza. Kiosk i will take crates[i] crates of stock tonight, and the array closes on itself: the last kiosk and the first kiosk stand side by side.
One van does the round, and it cannot serve two kiosks that stand next to each other, because the plaza only opens one bay at a time and neighbouring bays share a shutter. Serving no kiosk at all is allowed.
Return the largest number of crates the van can deliver in a single night.
Examples
Example 1
- Input
- crates = [7, 4, 9, 5]
- Output
- 16
Serving the first and third kiosk delivers 7 plus 9 crates; the other legal pair, the second and fourth, only manages 9 in total.
Example 2
- Input
- crates = [6, 6, 6]
- Output
- 6
On a ring of three every kiosk touches both others, so the van can serve only one of them.
Example 3
- Input
- crates = [0, 0]
- Output
- 0
Neither kiosk needs stock, so the van delivers nothing.
Constraints
- 1 <= crates.length <= 100
- 0 <= crates[i] <= 1000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_ring_restock(crates: list[int]) -> int:public int maxRingRestock(int[] crates)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's