Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

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

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

Correct answer: B. 4

The distinct substrings are a, aa, aaa and aaaa, so the count is 4. Counting by position would give 10.

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

Exams that ask this topic