Given an integer array of N integers, find sum of bit differences in all pairs that can be formed from array elements. Bit difference of a pair (x, y) is count of different bits at same positions in binary representations of x and y.
For example, bit difference for 2 and 7 is 2. Binary representation of 2 is 010 and 7 is 111 (first and last bits differ in two numbers).Note: (x, y) and (y, x) are considered two separate pairs.
- Time : O(n)
- Space : O(1)
1 | class Solution{ |