Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 486 Predict the Winner - Problem Statement

LeetCode 486

Two players take turns picking numbers from either end of an array. Each player adds the picked number to their score. Both play optimally. Can Player 1 win (or tie)? Example: nums =[1,5,2]= [1, 5, 2]. Player 1 picks 22, Player 2 picks 55, Player 1 picks 11. Scores: 33 vs 55. Player 1 loses.

But if Player 1 picks 11 first, then 55... try it yourself. This is the classic Game Theory DP problem. The array shrinks from both ends, and we need to track who's winning at each subarray.