Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B

What is the length of the longest substring of "bbaacabaacb" that contains EXACTLY two letters 'a'?

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

Correct answer: B. 5

Positions of the a's split the string into gaps; the longest valid substring spans from just after one a to just before the a that is two places later. Using a window that allows at most two a's gives a longer, wrong answer.

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

Exams that ask this topic