Problem Summary
Given N strings. Each string contains only lowercase letters from a to j(both inclusive). The set of N strings is said to be “GOOD SET” if no string is prefix of another string. Else, it is “BAD SET”.
(If two strings are identical, they are considered prefixes of each other.)
Solution
We use trie to store the set of strings.
For each string s[i], we try to add it to the set. Apparently, we need to make sure that
- s[i] is not a prefix of s[0],s[1],… or s[i-1].
- s[j] is not a prefix of s[i], for any j, 0 ≤ j < i.
Code
|
|