Question :↵
↵
Given 2 arrays 'A' and 'B' both of size 'N'. **Make 'N' pairs** ( A[ i ], B[ j ] ) such that : ↵
↵
1. First element of pair should be from array 'A' and second element from array 'B'. ( we cannot make pair ( A[1], A[3] ) )↵
2. 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) }↵
3. 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 ) ↵
↵
( Consider N even as the problem can be solved for odd N in O(N) easily )↵
↵
![ ](/predownloaded/a6/2c/a62cde6cf6a180e22e2872e8beb3c85eb6cf968f.jpg)↵
↵
How to solve it in less than O(N^2) Time Complexity ?↵
↵
If not possible return -1↵
↵
↵
Given 2 arrays 'A' and 'B' both of size 'N'. **Make 'N' pairs** ( A[ i ], B[ j ] ) such that : ↵
↵
1. First element of pair should be from array 'A' and second element from array 'B'. ( we cannot make pair ( A[1], A[3] ) )↵
2. 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) }↵
3. 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 ) ↵
↵
( Consider N even as the problem can be solved for odd N in O(N) easily )↵
↵
![ ](/predownloaded/a6/2c/a62cde6cf6a180e22e2872e8beb3c85eb6cf968f.jpg)↵
↵
How to solve it in less than O(N^2) Time Complexity ?↵
↵
If not possible return -1↵
↵