Could anyone explain why (5,12) is true?


  • 0
    S

    There is one test case (5,12). The expected output is true.

    It seems to be false. If the first player select 5, the second player can select 1, then no matter what is the next from first player, the second player wins. If the first player select one from [1,2,3,4], for example 1, the second player can select another one from 1-4, which make sum of two numbers as 5 -- i.e. 4 for the example, then the first player has no way to win.

    Is there anything wrong with my logic above? Thanks.


  • 0
    G

    @sgsg Suppose first player chooses 2

    Your strategy suggests the second player should choose 3 to make the sum 5.

    The first player can choose between {1,4,5}. If they choose 1, the sum becomes six, and no matter what the second player chooses, the first player would win.

    The guaranteed win actually comes when Player 1 chooses 3 first. Dash's separate players turns.

    3-1-2 {4,5} left for p2 to choose. Either way player 1 wins
    3-2-1- {4,5} left for p2 to choose. Either way player 1 wins
    3-4-5. P1 wins
    3-5-4. P1 wins


  • 0
    S

    Thank you for the explanation!


Log in to reply
 

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