Tap here to switch tabs
Problem
Submissions

Problem: Stone Game VI

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

Statement

Alice and Bob take turns playing a game with nn stones, where Alice plays first.

You are given two integer arrays, aliceValues and bobValues, both of length nn. If Alice chooses the stone at index i, she receives aliceValues[i] points. If Bob chooses the stone at index i, he receives bobValues[i] points.

On each turn, a player removes one unchosen stone from the game and adds its corresponding point value to their total score. The game ends when all stones have been removed. Both players play optimally to maximize their respective total scores.

Return 11 if Alice wins, −1-1 if Bob wins, and 00 if the game ends in a draw.

Constraints:

  • n == aliceValues.length == bobValues.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq aliceValues[i], bobValues[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Stone Game VI

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

Statement

Alice and Bob take turns playing a game with nn stones, where Alice plays first.

You are given two integer arrays, aliceValues and bobValues, both of length nn. If Alice chooses the stone at index i, she receives aliceValues[i] points. If Bob chooses the stone at index i, he receives bobValues[i] points.

On each turn, a player removes one unchosen stone from the game and adds its corresponding point value to their total score. The game ends when all stones have been removed. Both players play optimally to maximize their respective total scores.

Return 11 if Alice wins, −1-1 if Bob wins, and 00 if the game ends in a draw.

Constraints:

  • n == aliceValues.length == bobValues.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq aliceValues[i], bobValues[i] ≤100\leq 100