Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

What is the length of the longest substring of "aaabbbcaabbbcc" in which every letter occurring in it appears at least 3 times?

  1. A. 15
  2. B. 14
  3. C. 13
  4. D. 6

Correct answer: B. 14

The whole string qualifies, since a, b and c each occur at least 3 times, so no split is needed. Splitting at letters with fewer than k occurrences is the general method.

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

Exams that ask this topic