Data Structures & AlgorithmsModerateGATE CS · TCS NQT

What is the length of the longest substring of aabaaccaa that contains at most two letters 'a'?

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

Correct answer: A. 5

Use a sliding window that counts a's and shrinks when a third a enters. Counting only the other letters would give a different window.

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

Exams that ask this topic