Predict the Winner
Two players take turns picking a number from either the left or right end of the array nums, adding it to their score. Player 1 goes first. Assuming both play optimally to maximize their own score, return true if Player 1 can win (score at least as high as Player 2), otherwise false.
Open official problem prompt ↗Decide whether the first player can guarantee a non-losing score when both players pick greedily-optimally from the ends of the array.
Two chess players sharing a scorecard where only the gap matters: each move you widen your own lead, but you know your opponent will then try just as hard to close it, so you plan for the net swing rather than raw points.
- Input
- nums = [1, 5, 2]
- Output
- false
- Why
- Player 1 picks 2 (best end), then Player 2 picks 5, Player 1 gets 1: 3 vs 5, so Player 1 cannot win.
1 <= nums.length <= 200 <= nums[i] <= 10^7