i carries the number tokens[i]. Two players take turns removing one token of their choice, the first player moving first. Every removed token goes into a shared pile.
A player whose move makes the sum of the shared pile a multiple of 3 loses immediately. If the tokens run out and that never happened, the second player wins, even if it would be the first player's turn.
Both play optimally. Return True if the first player wins and False otherwise.tokens=[4, 5] → True
The first player takes either token, the second is left with the other one, and the sum becomes 9, a multiple of 3, so the second player loses.
tokens=[7] → False
The first player takes the only token; the sum 7 is not a multiple of 3, but the tokens have run out, so the second player wins.
tokens=[3, 6, 1] → False
tokens=[4, 5]
True
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.