'bitwise xor of all elements of A and that of all element of B is the same [closed]

You are given an array A having N integer You need to create a new array B having N non negative integer less than 2^25 such that bitwise XOR of all elements of A and that of all element of B is the same. Find the maximum possible sum of element of array B modulo 10^9+7

input Formate : First line Contanins an integer.N denoting the Number of element in A each line i of the N subsequent lines (Where 0 <= i < N) contains an integer describing A[i].



Solution 1:[1]

Consider this example with 8 bits. Say that A is (in hex):

11
22
44
05
07

The combined xor is 0x75. So, we start B with:

FF
FF
FF
FF

The combined xor of that is 0. So, we just add the A result:

FF
FF
FF
FF
75

That set produces the maximum possible sum. If the length is even, you have to use the inverse:

11
22
44
07

The xor sum is 70. So B must be:

FF
FF
FF
8F

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Roberts