Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

What is the length of the longest substring of "aabbaacc" in which every letter appears at most twice?

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

Correct answer: A. 6

Shrink the window when a letter's count exceeds two: 'aabbaa' fails (four a's), but 'bbaacc' (indices 2–7) is valid, length 6. 8 is the whole string, 2 allows each letter at most once, and 3 is a short window such as 'aab'.

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

Exams that ask this topic