Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: The string "ababa" has how many distinct substrings of length 2 and 3 combined?

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

Correct answer: D. 4

Collect the distinct substrings of each length separately and add the counts. Counting all positions (4 + 3) gives a larger number because of repeats.

More Coding Interview Problems questions

Exams that ask this topic