-2

Given n strings each of length <=10^5.

Input: “aa ab ac ad”

Output: 8 (“a”,”b”,”c”,”d”,”aa”,”ab”,”ac”,”ad”)

Input: “aab bcd”

Output: 10 (“a”,”b”,”c”,”d”,”aa”,”ab”,”bc”,”cd”,”aab”,”bcd”)

update:

suffix tree is one solution.But it takes more memory.

Is there any solution other than suffix tree?

pavaniiitn
  • 311
  • 1
  • 4
  • 18

1 Answers1

0

Suffix tree. You don't need to do anything other than set the suffix tree up, it is precisely a structure that lists all the distinct sub-strings of any string or set of strings.

Malcolm McLean
  • 6,258
  • 1
  • 17
  • 18