Tap here to switch tabs
Problem
Submissions

Problem: Predict the Winner

Predict the Winner gives two players an integer array. They alternately choose and remove a number from either end, playing optimally. Return whether player one can win or tie.

Statement

You are given an integer array nums. Two players take turns choosing a number from either end of the array. Each chosen number is added to the choosing player’s score, and the chosen element is removed from the array.

Both players play optimally. Return true if player 11 can win or tie the game, and false otherwise.

Note: A player wins if their score is greater than or equal to the other player’s score.

Constraints:

  • 1 <= nums.length <= 20

  • 0 <= nums[i] <= 10^7

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Predict the Winner

Predict the Winner gives two players an integer array. They alternately choose and remove a number from either end, playing optimally. Return whether player one can win or tie.

Statement

You are given an integer array nums. Two players take turns choosing a number from either end of the array. Each chosen number is added to the choosing player’s score, and the chosen element is removed from the array.

Both players play optimally. Return true if player 11 can win or tie the game, and false otherwise.

Note: A player wins if their score is greater than or equal to the other player’s score.

Constraints:

  • 1 <= nums.length <= 20

  • 0 <= nums[i] <= 10^7