Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many non-empty subarrays of [1, 2, 1, 2, 3, 3, 1] contain every value an even number of times?

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

Correct answer: D. 4

Track the parity mask of counts: a subarray is valid when its prefix parity mask at both ends is equal. Counting equal masks among prefixes gives the count in linear time.

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

Exams that ask this topic