Token Game
Alex and Blake play a game with a pile of K tokens. They take turns removing tokens from the pile, with Alex going first. On each turn, a player can remove exactly x tokens, where x must be an element from a given set of n allowed moves A = {A1, A2, ..., An}. The player who cannot make a valid move loses.
Assuming both players play optimally, determine the winner. Return "First" if Alex wins, or "Second" if Blake wins.
Example 1:
Input: n = 2, K = 4 ,A = [1,3]
Output: Second
Explanation:
- From 4:
- remove 1 → 3
- remove 3 → 1
Both lead to winning positions for Second.
Example 2:
Input: n = 3, K = 5 , A = [1,3,4]
Output: First
Explanation:
- First can force a win by choosing moves strategically.
Now Your Turn!
Pick the correct output for the given inputInput: n = 3 , K = 10 , A = [2,3,5]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
1 <= n <= 100
1 <= K <= 105
1 <= A1 < A2 < ... < An <= K