Tap here to switch tabs
Problem
Submissions

Problem: Stone Game VII

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

Statement

Alice and Bob play a game with a row of stones represented by an integer array stones.

Alice takes the first turn, and the players alternate turns thereafter. On each turn, the current player removes either the first stone or the last stone from the remaining row. The player is awarded points equal to the sum of all remaining stones currently in the row. The game concludes when all stones have been removed.

Alice aims to maximize the difference between her final score and Bob’s final score, while Bob aims to minimize this difference.

Return the final score difference between Alice and Bob, assuming both players play optimally.

Constraints:

  • n=n = stones.length

  • 2≤n≤10002 \leq n \leq 1000

  • 1≤1 \leq stones[i] ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Stone Game VII

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

Statement

Alice and Bob play a game with a row of stones represented by an integer array stones.

Alice takes the first turn, and the players alternate turns thereafter. On each turn, the current player removes either the first stone or the last stone from the remaining row. The player is awarded points equal to the sum of all remaining stones currently in the row. The game concludes when all stones have been removed.

Alice aims to maximize the difference between her final score and Bob’s final score, while Bob aims to minimize this difference.

Return the final score difference between Alice and Bob, assuming both players play optimally.

Constraints:

  • n=n = stones.length

  • 2≤n≤10002 \leq n \leq 1000

  • 1≤1 \leq stones[i] ≤1000\leq 1000