Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many substrings of abcabc contain all of the three letters a, b and c at least once?

  1. A. 11
  2. B. 8
  3. C. 10
  4. D. 13

Correct answer: C. 10

Count, for each left end, the shortest right end that completes all three letters; every later right end also works. Summing these per-left counts avoids enumerating all substrings.

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

Exams that ask this topic