Total Hamming Distance Problem

Total Hamming Distance Problem — ExecCode Easy DSA Practice

Solve the Total Hamming Distance problem on ExecCode. Free online easy DSA practice in Bit Manipulation. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums. Your task is to the Hamming distance between two integers is the number of positions at which the corresponding bits are different. Return the required answer exactly as shown in the examples.

Examples

Input {"nums": [1, 3, 5, 7, 9, 11, 13, 15]}; Output 48. Input {"nums": [4, 14, 4]}; Output 4. Input {"nums": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}; Output 112

Constraints

1 <= nums.length <= 10^4 0 <= nums[i] <= 10^9 The answer for the given input will fit in a 32-bit integer.

Practice Total Hamming Distance free on ExecCode. Browse DSA problems, topic map, and placement guides.