Data Structures & AlgorithmsModerateProduct-company MCQ pattern

How many distinct non-empty substrings does the string ABAB have?

  1. A. 7
  2. B. 8
  3. C. 6
  4. D. 10

Correct answer: A. 7

There are 4 × 5/2 = 10 substrings by position, but A, B and AB each appear twice, so the distinct ones are A, B, AB, BA, ABA, BAB, ABAB = 7.

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

Exams that ask this topic