Tap here to switch tabs
Problem
Submissions

Problem: Stone Game II

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

Statement

Alice and Bob are playing a game with piles of stones arranged in a row, where the number of stones in each pile is given by the integer array piles.

Alice begins the game. At the start, the value of M is set to 11.

On each turn, a player can take all the stones from the first X remaining piles, where 1≤X≤2M1 \leq X \leq 2M. Following this move, the value of M is updated to max⁡(M,X)\max(M, X).

The game continues until all piles have been taken. Assuming both Alice and Bob play optimally to maximize their total number of stones, return the maximum number of stones Alice can obtain.

Constraints:

  • 1≤1 \leq piles.length ≤100\leq 100

  • 1≤1 \leq piles[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Stone Game II

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

Statement

Alice and Bob are playing a game with piles of stones arranged in a row, where the number of stones in each pile is given by the integer array piles.

Alice begins the game. At the start, the value of M is set to 11.

On each turn, a player can take all the stones from the first X remaining piles, where 1≤X≤2M1 \leq X \leq 2M. Following this move, the value of M is updated to max⁡(M,X)\max(M, X).

The game continues until all piles have been taken. Assuming both Alice and Bob play optimally to maximize their total number of stones, return the maximum number of stones Alice can obtain.

Constraints:

  • 1≤1 \leq piles.length ≤100\leq 100

  • 1≤1 \leq piles[i] ≤104\leq 10^4