Friday, July 28th
Can player 1 win?
Two players are in a game. The game has an array. At each turn, beginning with player 1, a player selects a value from the beginning or end of the array. The value is added to the player's score. Each selection reduces the size of the array by 1. After all values have been selected, the player with the highest score wins. Return true if planer 1 can with the game.
One key observation is that it's not asking for a maximum or minimum like most dp problems, but it's looking to see if player 1 can win. Victory can be determined by the difference in scores.
Also, a player can choose either the right or the left value. This leads to the dp recurrence relation:
Shout out to the Editorial for clearing up how the score difference can be applied to a dynamic programming problem like Max Score Performing Multiplies
Comments
Post a Comment