Variation in Nim Game
Submissions: 333   Accuracy:

48.95%

  Difficulty: Easy   Marks: 2

You are given an array A[] of n-elements. There are two players Alice and Bob. A Player can choose any of element from an array and remove it. If the bitwise XOR of all remaining elements equals 0 after removal of the selected element, then that player loses.
Note: Each player play game alternately. Find out a winner if both of the players play optimally. Alice starts the game first. In case one-element in array consider its value as the XOR of an array.

Input:
The first line contains an integer T, number of test cases. For each test case, the first line contains an integer n,  denoting the size of the array A. Next line contains n-space separated integers denoting the elements of the array A.

Output:
For each test case, the output is 1 if Alice wins or 2 if Bob wins.

Constraints:
1<=T<=100
1<=n<=50

Example:
Input
2
3
3 3 2
2
3 3
Output
2
1

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Vanshika
Author: Vanshika_pec


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.