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:
stones.length
stones[i]
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:
stones.length
stones[i]