algorythms
Game Theory & Minimax
LC #486Medium

Predict the Winner

Game Theory & Minimax

Problem

Two players take turns picking from either end of an array. Return true if player 1 can secure a score >= player 2.

arraydynamic-programmingmathgame-theory

Constraints

  • 1 ≤ nums.length ≤ 20
  • 0 ≤ nums[i] ≤ 10⁷

Example

Inputnums = [1, 5, 2]
Outputfalse
Why

P1 takes 1. P2 takes 5. P1 takes 2. Score: P1=3, P2=5. P1 loses.

Hints — reveal one at a time