Data Structures & AlgorithmsHard

How many contiguous subarrays of [5, 5, 3, 3, 6, 6, 6] have XOR equal to 0?

  1. A. 4
  2. B. 7
  3. C. 6
  4. D. 8

Correct answer: B. 7

Equal prefix XOR values bracket a zero-XOR subarray, so count pairs of equal prefix XORs including the initial 0. The claim that XOR-zero subarrays must have even length is false, and skipping the initial prefix also loses answers.

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

Exams that ask this topic