Tap here to switch tabs
Problem
Submissions

Problem: Stone Game

med
30 min
Try to solve the Stone Game problem.

Statement

Alice and Bob play a game with piles of stones arranged in a row.

There is an even number of piles, where piles[i] represents the number of stones in the iextthi^{ ext{th}} pile. The total number of stones across all piles is odd, so there can be no ties.

Alice and Bob take turns, with Alice making the first move. On each turn, a player takes all the stones from either the beginning or the end of the current row of piles. This continues until no piles remain. The player with the higher total number of stones wins.

Assuming both players play optimally, return true if Alice wins the game, or false otherwise.

Constraints:

  • 2≤2 \leq piles.length ≤500\leq 500

  • piles.length is even.

  • 1≤1 \leq piles[i] ≤500\leq 500

  • sum(piles[i]) is odd.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Stone Game

med
30 min
Try to solve the Stone Game problem.

Statement

Alice and Bob play a game with piles of stones arranged in a row.

There is an even number of piles, where piles[i] represents the number of stones in the iextthi^{ ext{th}} pile. The total number of stones across all piles is odd, so there can be no ties.

Alice and Bob take turns, with Alice making the first move. On each turn, a player takes all the stones from either the beginning or the end of the current row of piles. This continues until no piles remain. The player with the higher total number of stones wins.

Assuming both players play optimally, return true if Alice wins the game, or false otherwise.

Constraints:

  • 2≤2 \leq piles.length ≤500\leq 500

  • piles.length is even.

  • 1≤1 \leq piles[i] ≤500\leq 500

  • sum(piles[i]) is odd.