Now, after trying on these examples, we can generalize the if n is odd, then first player will lose, otherwise he will win.
QUICK EXPLANATION:
If A1⊕A2⊕A3⋯⊕AN=0A1⊕A2⊕A3⋯⊕AN=0, then the first player wins.
Otherwise
If N is odd, then first player will win.
If N is even, then the second player will win.
Thought too much and executed very little on the simple lines,I was thinking about too many different testcases. Was worrying about the counts of same number stone piles, when the trick was
XOR mattered only for the very first time at the start
Damn, I actually XORed each element with the full set’s XOR to see if it could be removed (i.e. it did not lead to a zero) and accordingly removed that element. It worked but this is neat.
I simply simulated playing of whole game. A player will try to remove that pile after whose removal there is remaining piles with non zero XOR.Since constraints were very small so it got executed. Link
Someone please clear my doubt by giving a test case.I didn’t checked the first condition of xoring all elements and checking if its zero…directly checked if N is odd or even.Because I feel that there is no way of getting xor=0 if N is odd.Someone please prove me wrong!
I think the answer should be First only. Say first player removes pile with number 2 then i have 5 piles with same number so the second player will remove one of those piles leaving equal piles in even numbers so answer of XOR is zero hence first wins. Do comment if i am wrong