Data Structures & AlgorithmsModerateCodeforces Div2 B · TCS NQT

How many DISTINCT substrings of length exactly 3 does "abcabcbb" contain?

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

Correct answer: B. 5

A rolling hash or a set over all length-3 windows gives the distinct count, while the number of windows (n − 2) counts repeats. Counting distinct letters answers a different question.

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

Exams that ask this topic