1323. Total Hamming Distance for All Pairs

EasyBit ManipulationBit ManipulationCountingPairs

Given an array of non-negative integers, return the sum of the Hamming distances between every unordered pair of elements.

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

Output: Return the total Hamming distance over all pairs (i < j).

Examples

Example 1
Input: {"nums":[4,14,2]}
Output: 6
Explanation: The three pairwise distances sum to 6.
Example 2
Input: {"nums":[5,5]}
Output: 0
Explanation: Equal values -> distance 0.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →