Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many index pairs i < j in [3, 5, 6, 9, 10] have a[i] XOR a[j] with an odd number of 1-bits?

  1. A. 1
  2. B. 2
  3. C. 0
  4. D. 3

Correct answer: C. 0

The popcount of a XOR b has the parity of (popcount a + popcount b). Pairs with different parity of popcount are exactly the odd ones, and that shortcut matches the direct count.

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

Exams that ask this topic