Stone Game
Alice and Bob play with an even-length array piles where piles[i] is the number of stones in pile i and the total is odd. They alternate turns, Alice first, each taking a whole pile from either the left or right end. The player with more stones wins. Assuming optimal play, return true if Alice wins.
Open official problem prompt ↗Determine whether Alice, moving first and playing optimally, ends with strictly more stones than Bob.
Two people splitting a row of gift boxes from the ends, each trying to maximize the net lead; you plan around the swing in the lead rather than counting boxes twice.
- Input
- piles = [5, 3, 4, 5]
- Output
- true
- Why
- Alice takes the right 5; whatever Bob takes, Alice takes the other 5, guaranteeing at least 10 of the 17 stones.
2 <= piles.length <= 500piles.length is even1 <= piles[i] <= 500sum(piles) is odd