Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many DISTINCT substrings (by content, non-empty) does "abcab" have?

  1. A. 12
  2. B. 15
  3. C. 11
  4. D. 3

Correct answer: A. 12

There are n(n+1)/2 substring positions, but repeated contents must be merged. A suffix automaton or suffix array gives the count in O(n log n); counting positions (not contents) gives the larger number.

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

Exams that ask this topic