Leaderboard
Showing:
Sum of XOR of all pairs
Medium Accuracy: 35.3% Submissions: 17 Points: 4

Given an array of N integers, find the sum of xor of all pairs of numbers in the array.

Example 1:

​Input : arr[ ] = {7, 3, 5}
Output : 12
Explanation:
All possible pairs and there Xor
Value: ( 3 ^ 5 = 6 ) + (7 ^ 3 = 4)
 + ( 7 ^ 5 = 2 ) =  6 + 4 + 2 = 12


​Example 2:

Input : arr[ ] = {5, 9, 7, 6} 
Output :  47

 

Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function sumXOR() that takes an array (arr), sizeOfArray (n), and returns the sum of xor of all pairs of numbers in the array. The driver code takes care of the printing.

Expected Time Complexity: O(N Log N).
Expected Auxiliary Space: O(1).


Constraints
2 ≤ N ≤ 10^5
1 ≤ A[i] ≤ 10^5

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Sum of XOR of all pairs

Output Window