Predict the Winner

Hard

Topics
ArrayMathDynamic ProgrammingGame Theory

Given a score array nums, two players take turns picking a number from either end; the picked value is added to that player's score. Player 1 moves first. Both play optimally. Return true if player 1 can end with a score greater than or equal to player 2.

Example 1

Input:  nums = [1,5,2]
Output: false

Example 2

Input:  nums = [1,5,233,7]
Output: true

Constraints

  • 1 <= nums.length <= 20
  • 0 <= nums[i] <= 10^7
Run ⌘' · Submit ⌘⏎