Data Structures & AlgorithmsModerateGATE CS · TCS NQT

How many distinct substrings of length 3 of abcabcabc occur at least twice in the string?

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

Correct answer: A. 3

The windows of length 3 are abc, bca, cab, abc, bca, cab, abc; the distinct ones that repeat are abc, bca and cab, so the answer counts all three.

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

Exams that ask this topic