Two players take turns removing a number from either end of nums, and add it to their score. Player 1 moves first and both play optimally. Return true if Player 1 can win; a tie also counts as a win for Player 1.
Two players take turns removing a number from either end of nums, and add it to their score. Player 1 moves first and both play optimally. Return true if Player 1 can win; a tie also counts as a win for Player 1.
Example 1:
Input: {"nums":[1,5,2]}
Output: false
Constraints:
1≤nums.length≤20
0≤nums[i]≤107
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,5,2]}
dp[i][j] = how far ahead the player to move can finish on nums[i..j] (their total minus the other player's). Player 1 wins if dp[0][2] >= 0.
nums: the window [i..j] is the game still to be played
1
0
5
1
2
2
dp[i][j] (row i, column j): lead of the player to move on nums[i..j]