1317. Sum of Bit Differences Among All Pairs

EasyBit ManipulationBit ManipulationCountingPairs

Given an array of non-negative integers, return the sum over all ordered pairs (i, j) of the number of differing bits between nums[i] and nums[j]. Ordered pairs count both (i, j) and (j, i).

Input: A JSON object {"nums": [<non-negative integers>]}.

Output: Return the total bit-difference sum over all ordered pairs.

Examples

Example 1
Input: {"nums":[1,3,5]}
Output: 8
Explanation: Over all ordered pairs the differing bits total 8.
Example 2
Input: {"nums":[2,2]}
Output: 0
Explanation: Equal values differ in no bits -> 0.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →