Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

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

  1. A. 9
  2. B. 4
  3. C. 21
  4. D. 10

Correct answer: D. 10

For each start, the substring qualifies once it reaches the first index where all three letters have appeared: starts 0..3 contribute 4 + 3 + 2 + 1 = 10. Counting distinct strings gives 9, counting only length-3 windows gives 4, and 21 counts all substrings.

More Coding Interview Problems questions

Exams that ask this topic