Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6381
@blackshadows 6329
@mb1973 5388
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Sum of XOR of all pairs
Medium Accuracy: 54.31% Submissions: 109 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