ProgrammingVery hardGATE CS · Campus placements

int a[] = {3, 5, 6, 9}; int pre[5]; pre[0] = 0, and pre[i] = pre[i-1] ^ a[i-1] for i = 1..4. What is pre[4] ^ pre[1]?

  1. A. 10
  2. B. 3
  3. C. 12
  4. D. 14

Correct answer: A. 10

pre[4] ^ pre[1] equals a[1] ^ a[2] ^ a[3] = 5 ^ 6 ^ 9 = 10. Prefix XOR arrays answer any range XOR this way in O(1) per query.

More C Programming questions

Exams that ask this topic