Data Structures & AlgorithmsVery hard

Which statement about subarrays with XOR equal to 0 is CORRECT?

  1. A. Such a subarray must have even length.
  2. B. The prefix XOR array must be strictly increasing for the count to be valid.
  3. C. Two prefix-XOR values are equal exactly when the subarray between them has XOR 0.
  4. D. Subarray XOR cannot be derived from prefix XOR values.

Correct answer: C. Two prefix-XOR values are equal exactly when the subarray between them has XOR 0.

If p[i] = p[j] then the XOR of elements i..j−1 cancels to 0, and the converse holds too. Length 3 subarrays such as [1, 2, 3] can have XOR 0, so the even-length claim is false.

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

Exams that ask this topic