Practice Stone Game VIII
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Alice and Bob alternate, with Alice first. While more than one stone remains, choose at least two leftmost stones, add their summed value to the current player score, and replace them with a single stone of that sum at the left end. Alice maximizes and Bob minimizes Alice score minus Bob score. Return that difference under optimal play.
Source: Stone Game VIII on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
stones = [-1,2,-3,4,-5]
Output
5
# Example 2
Input
stones = [7,-6,5,10,5,-2,-6]
Output
13
# Example 3
Input
stones = [-10,-12]
Output
-22
Constraints
n == stones.length
2 <= n <= 10^5
-10^4 <= stones[i] <= 10^4
Related LeetCode Problems
Practice more problems similar to Stone Game VIII.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.