Practice/Amazon/Leetcode 486. Predict the Winner
CodingMust
Two players are competing in a stone collection game. They have a row of stones, each with a certain point value. Players take turns selecting a stone from either the leftmost or rightmost position of the remaining row. The selected stone is removed and its value is added to that player's score.
Player 1 always goes first. Both players play optimally, meaning each player makes the move that maximizes their chances of winning.
Your task is to determine whether Player 2 can guarantee a win or at least a tie against Player 1. Return true if Player 2 can guarantee not losing (win or tie), and false otherwise.
true)Example 1:
` Input: stones = [1, 5, 2] Output: false Explanation:
Actually with optimal play:
Example 2:
Input: stones = [1, 5, 233, 7] Output: true Explanation: Player 2 can guarantee at least a tie with optimal strategy.
Example 3:
Input: stones = [10] Output: false Explanation: Player 1 takes the only stone and wins 10-0.