Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

What is the sum of Hamming distances (number of differing bit positions) over all unordered pairs of [1, 3, 5, 7]?

  1. A. 8
  2. B. 10
  3. C. 6
  4. D. 16

Correct answer: A. 8

Summing popcount(x XOR y) over all six unordered pairs gives the total. The column method (for each bit, count of ones times count of zeros) gives the same total.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic