Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional

What is the length of the longest substring of "aabbcabccbba" in which every letter occurs an EVEN number of times (0 counts as even)?

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

Correct answer: A. 4

Track the parity mask of letter counts over the prefix; a substring has all-even counts when two prefixes share the same mask, so the longest gap between equal masks is the answer. Checking only each letter's count parity along a window is slower and easy to get wrong.

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

Exams that ask this topic