Data Structures & AlgorithmsHardGATE CS · competitive programming

How many non-empty contiguous subarrays of [1, 2, 3, 0, 3] have XOR equal to 0?

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

Correct answer: B. 4

Zero-XOR ranges are the ones whose prefix XORs match. They are [1,2,3], [1,2,3,0], [3,0,3] and [0]; the two 3s in [3,0,3] cancel.

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

Exams that ask this topic