Even-Odd Game
Two players, First and Second, are playing a game with an integer array nums. First moves first, and they take alternating turns.
In each turn, a player removes one element from the array:
- If First removes an even number, they add it to their score. If they remove an odd number, their score does not change.
- If Second removes an odd number, they add it to their score. If they remove an even number, their score does not change.
The game ends when the array is empty. Assuming both players play optimally to maximize their chances of winning, return "First" if First wins, "Second" if Second wins, or "Draw" if their final scores are equal.
Example 1:
Input: nums = [3, 2, 1]
Output: "Draw"
Explanation:
First optimally removes 3 (+0).
Second removes 2 (+0).
First removes 1 (+0). Both end with a score of 0.
Example 2:
Input: nums = [5, 2, 7, 3]
Output: "Second"
Explanation:
1. First takes 7 (scores 0) to block Second.
2. Second takes 5 (scores 5).
3. First takes 3 (scores 0).
4. Second takes 2 (scores 0). Final Score — First: 0, Second: 5. Second wins.
Now Your Turn!
Pick the correct output for the given inputInput: nums = [2, 2, 2 , 2 ]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 2 * 105
- 1 <= nums[i] <= 109