Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

What is the XOR of the elements at indices 2 through 6 (inclusive) of [5, 8, 1, 9, 4, 3, 7, 2]?

  1. A. 15
  2. B. 0
  3. C. 8
  4. D. 9

Correct answer: C. 8

Prefix XOR gives any range XOR as pre[r+1] XOR pre[l]. Off-by-one errors on either bound change the result by one term.

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

Exams that ask this topic