Question :
Given 2 arrays 'A' and 'B' both of size 'N'. Make 'N' pairs ( A[ i ], B[ j ] ) such that :
- First element of pair should be from array 'A' and second element from array 'B'. ( we cannot make pair ( A[1], A[3] ) )
- An element cannot occur in more than one pair. { i.e for every 2 pairs ( A[i], B[j] ) , ( A[k], B[l] ) (i != k and j != l) }
- Let the value of a pair be the XOR of first and second element of the pair, value of all the pairs formed must be equal.
Constraints : 0 <= A[i], B[i] <= 10^9 __________ ( 1 <= i <= N )
How to solve it in less than O(N^2) Time Complexity ?
If not possible return -1