Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: The string "abcabcabc" has how many distinct substrings of length 3?

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

Correct answer: A. 3

The distinct length-3 substrings are abc, bca and cab, since the string is periodic with period three. Counting positions (7) overstates the distinct count.

More Coding Interview Problems questions

Exams that ask this topic