Second Example?


  • 0
    J

    How does player 1 win in the second example?


    Input: [1, 5, 233, 7]
    Output: True
    Explanation: Player 1 first chooses 1. Then player 2 have to choose between 5 and 7. No matter which number player 2 choose, player 1 can choose 233.
    Finally, player 1 has more score (234) than player 2 (12), so you need to return True representing player1 can win.


    Why would player 1 choose 1 instead of 7 for their first move? It says in the description that each player is playing to maximize their score. This test case prevented me from having my code accepted.

    Isn't this how play should go?
    Start: [1, 5, 233, 7]
    Player 1: Picks 7, Score = 7 ([1, 5, 233])
    Player 2: Picks 233, Score = 233 ([1, 5])
    Player 1: Picks 5, Score = 12 ([1])
    Player 2: Picks 1, Score = 234 ([])


  • 0
    L

    Both players want to win. So player1 chooses 1 because he knows that no matter what player2 choose, he will get 233 and win.


  • 0
    J

    Okay, sorry, I just assumed that they would always pick the larger of the two numbers.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.