Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Take the XOR of a[i] XOR a[j] over all pairs i < j in [1, 2, 3, 4]. How many set bits (1-bits) does this combined XOR have?

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

Correct answer: C. 1

Each element appears in n - 1 pairs, so the combined XOR depends only on parity. Computing the pairwise XOR values directly gives the same result.

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

Exams that ask this topic