FunctionRacerProblemsRace

Differing Bits Over All Pairs

MediumBitsPython, JavaScript, TypeScript, Java, C++

Two numbers differ at a bit position when one of them has a 1 there and the other has a 0. For every pair of positions i < j of nums, count the bit positions at which nums[i] and nums[j] differ.

Return the sum of these counts over all the pairs.

Example 1

nums [1,2,3]
returns 4

1 and 2 are 01 and 10: two bits differ. 3 is 11 and differs from each of them in one bit. 2 + 1 + 1 = 4.

Example 2

nums [7,7]
returns 0

The two numbers are equal, so no bit differs.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems