Sum of Hamming distances
Your task
The Hamming distance between two integers is the number of bit positions where they differ. Given an array nums of non-negative integers (each fits in 32 bits), return the sum of Hamming distances over all unordered pairs of elements. There can be up to 10^4 numbers, so an O(n^2) pairwise comparison is too slow.
Examples
total_hamming_distance(nums: list[int]) -> intExample 1
Input
total_hamming_distance([4, 14, 2])Output
6