Welcome to the daily solving of our PROBLEM OF THE DAY with Devashish Khare. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Bit Magic but will also help you build up problem-solving skills.
In this problem, we are given, an array of N integers, find the sum of xor of all pairs of numbers in the array arr. In other words, select all possible pairs of i and j from 0 to N-1 (i<j) and determine the sum of all (arri xor arrj).
Example :
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
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/sum-of-xor-of-all-pairs0723/1