Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C

Problem: How many subarrays of [1, 2, 3, 0, 3, 2, 1] have a XOR of zero?

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

Correct answer: A. 8

Prefix XORs are 0, 1, 3, 0, 0, 3, 1, 0; equal values bound zero-XOR subarrays: C(4,2) + C(2,2) + C(2,2) = 6 + 1 + 1 = 8. Skipping the single-element [0] gives 7, testing sum instead of XOR gives 1, and counting only subarrays that start at index 0 gives 3.

More Coding Interview Problems questions

Exams that ask this topic