Stone Game
Real-world version: Shelf End Bidding DuelThe statement here is our own: the same inputs, outputs and technique.
A closing auction lines up piles sealed bins on a shelf, left to right. Bin i contains piles[i] tokens.
Iris claims a bin first, then Odell, and they keep alternating. A claim always takes one whole bin from either the far left or the far right of whatever is still on the shelf, and every token inside a claimed bin is credited to whoever claimed it. The duel ends when the shelf is bare, and by then every bin has been claimed.
Each of them plays for the largest personal token total they can force, whatever the other one does.
Return true if Iris finishes with a strictly larger token total than Odell, and false otherwise.
Examples
Example 1
- Input
- piles = [3, 9, 1, 2]
- Output
- true
Iris ends the duel with a strictly larger token total than Odell, so true is returned.
Example 2
- Input
- piles = [1, 2]
- Output
- true
Iris claims the right-hand bin for 2 tokens, Odell is left with the bin holding 1, and 2 beats 1.
Example 3
- Input
- piles = [5, 4, 3, 1]
- Output
- true
Iris finishes ahead of Odell over the four claims.
Example 4
- Input
- piles = [2, 7, 4, 8, 9, 1]
- Output
- true
Iris finishes with a larger total than Odell across the six claims, so true is returned.
Constraints
- 2 <= piles.length <= 500
- piles.length is even.
- 1 <= piles[i] <= 500
- sum(piles[i]) is odd.
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 first_bidder_wins(bins: list[int]) -> bool:public boolean firstBidderWins(int[] bins)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 4 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