Tap here to switch tabs
Problem
Submissions

Problem: Stone Game III

med
30 min
Try to solve the Stone Game III problem.

Statement

Alice and Bob are playing a game with several piles of stones arranged in a row. An integer array stoneValue represents the values of these piles.

Alice goes first, and the two players take turns. On each player’s turn, that player can take 11, 22, or 33 piles from the beginning of the remaining piles. The score of a player is the sum of the values of the stones they collect. The game ends when all the piles have been taken.

Both players play optimally to maximize their total scores. The player with the higher total score wins. If both players end with the same score, the game results in a draw.

Determine the winner of the game. Return "Alice" if Alice wins, "Bob" if Bob wins, or "Tie" if the game ends in a draw.

Constraints:

  • 1≤1 \leq stoneValue.length ≤5imes104\leq 5 imes 10^4

  • −1000≤-1000 \leq stoneValue[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Stone Game III

med
30 min
Try to solve the Stone Game III problem.

Statement

Alice and Bob are playing a game with several piles of stones arranged in a row. An integer array stoneValue represents the values of these piles.

Alice goes first, and the two players take turns. On each player’s turn, that player can take 11, 22, or 33 piles from the beginning of the remaining piles. The score of a player is the sum of the values of the stones they collect. The game ends when all the piles have been taken.

Both players play optimally to maximize their total scores. The player with the higher total score wins. If both players end with the same score, the game results in a draw.

Determine the winner of the game. Return "Alice" if Alice wins, "Bob" if Bob wins, or "Tie" if the game ends in a draw.

Constraints:

  • 1≤1 \leq stoneValue.length ≤5imes104\leq 5 imes 10^4

  • −1000≤-1000 \leq stoneValue[i] ≤1000\leq 1000