All problems
0331MediumArrayMathDynamic ProgrammingMinimaxGame TheoryZero-Sum Game

Shelf End Bidding Duel

Tracked in this browser only
Write code

Trains the technique from

LeetCode 877Stone Game

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def first_bidder_wins(bins: list[int]) -> bool:
Java
public boolean firstBidderWins(int[] bins)
September 7
Apply