4 (100) and 7 (111) have a difference of 2.
Given an array values, return the sum of differences over all pairs of elements; each unordered pair of distinct positions counts once.
Checking every pair is O(n²); try to do better.values=[5, 3, 6] → 6
5 = 101, 3 = 011, 6 = 110. The pairs 5/3, 5/6 and 3/6 each differ in 2 bits, 6 in total.
values=[8, 8, 0] → 2
The two 8s match (0), and each differs from 0 in one bit: 0 + 1 + 1 = 2.
values=[7] → 0
values=[5, 3, 6]
6
Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.