Tap here to switch tabs
Problem
Submissions

Problem: Total Hamming Distance

med
30 min
Try to solve the Total Hamming Distance problem.

Statement

Given an integer array nums, calculate the total Hamming distance between every pair of distinct elements.

The Hamming distance between two integers is the number of bit positions at which their binary representations differ.

Return the sum of the Hamming distances for all unordered pairs of elements in nums.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • 0≤0 \leq nums[i] ≤109\leq 10^9

  • The result fits in a 3232 bit integer.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Total Hamming Distance

med
30 min
Try to solve the Total Hamming Distance problem.

Statement

Given an integer array nums, calculate the total Hamming distance between every pair of distinct elements.

The Hamming distance between two integers is the number of bit positions at which their binary representations differ.

Return the sum of the Hamming distances for all unordered pairs of elements in nums.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • 0≤0 \leq nums[i] ≤109\leq 10^9

  • The result fits in a 3232 bit integer.