prachi jain prachi jain

Let’s start the solution step by step. We have total of three option for the XOR of array and this game.

XOR of array is already 0: In this case Alice will unable to make a move and hence Alice is winner.

XOR of array is not zero: Now, in this case we have two options, either size of array will be odd or even.

CASE A: If the array size is odd then for sure Bob will win the game.

CASE B: If the array size is even then Alice will win the game.

Above conclusion can be proved with the help of mathematical induction.

Let A[] = {1} i.e. size of array is odd and XOR of array is non-zero: In this case Alice can select element 1 and then A[] will become empty and hence XOR of array can be considered as zero. Resulting Bob as winner.

Let size of array is even and XOR of array is non-zero. Now we can prove that Alice can always find an element to remove such that XOR of remaining elements of array will be non-zero.
To prove this lets start from the contradiction i.e. suppose whatever element you should choose XOR of remaining array must be zero.
So, let A1 Xor A2 Xor … An = X and n is even.
As per our contradiction hypothesis, Ai Xor X = 0 for 1<= i <= n.
Calculate XOR of all X Xor Ai (i.e. n equations),
After taking XOR of all n equations we have X Xor X…Xor X (n-times) = 0 as N is even.
Now, also we have A1 Xor A2 Xor.. An = 0 but we know A1 Xor A2…Xor = X. This means we have at least one element in even-size array such that after its removal XOR of remaining elements in non-zero.

Let size of array is even and XOR of array is non-zero. Alice can not remove an element Ai such that xor of remaining number is zero, because that will make Bob win. Now, take the other case when the xor of remaining N?1 number is non-zero. As we know that N?1 is even and from the induction hypothesis, we can say that the position after the current move will be a winning position for Bob. Hence, it is a losing position for Alice.

prachi jain

prachi jain Creator

(No description available)

Suggested Creators

prachi jain