Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5701 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 938 |
@bt8816103042 | 739 |
@SHOAIBVIJAPURE | 428 |
@codeantik | 412 |
@SherlockHolmes3 | 407 |
@neverevergiveup | 348 |
@mahlawatep | 347 |
@shalinibhataniya1097 | 343 |
@murarry3625 | 333 |
@saiujwal13083 | 326 |
@rohitanand | 314 |
Complete Leaderboard |
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
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes