Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

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 ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access