Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

How many substrings of "abcabcb" contain at least one each of the letters a, b and c?

  1. A. 18
  2. B. 11
  3. C. 14
  4. D. 28

Correct answer: C. 14

Count with a sliding window: for each left end, the smallest right end where all three letters appear determines how many right ends are valid (n − right + 1). Counting only substrings of length three misses longer valid ones.

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

Exams that ask this topic