This is an interview question:
Given a string, find all its permutations that are a word in dictionary.
My solution:
Put all words of the dictionary into a suffix tree and then search each permutation of the string in the tree.
The search time is O(n)
, where n
is the size of the string. But the string may have n!
permutations.
How do I improve the efficiency?