Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

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

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

Correct answer: B. 3

Prefix XORs: a subarray has XOR 0 exactly when two prefix XOR values are equal, so count equal pairs of prefixes with a hash map. Forgetting that the prefix of length 0 has XOR 0 loses some subarrays.

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

Exams that ask this topic