dsa · easy
Nim Game
A pile starts with n stones. Two players alternate. On a turn a player must take 1, 2, or 3 stones (never more than the pile holds). The player who takes the last stone wins. You move first, and both players play perfectly. Return whether you have a winning strategy.
Example
n = 1: the pile is a single stone. You take it and win immediately → true.
n = 4: every legal first move leaves 3, 2, or 1 stones. Your opponent then takes the rest and wins. You lose → false.
n = 5: take 1 stone, leave 4. Now your opponent is in the losing spot above, so you win → true.
## Arguments - n — number of stones in the starting pile
Constraints
1 <= n <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 1 Expected: true
Example 2
Input: 4 Expected: false
Example 3
Input: 5 Expected: true