![]() |
VOOZH | about |
Given a dictionary and a character array, print all valid words that are possible using characters from the array.
Examples:
Input : Dict - {"go","bat","me","eat","goal", "boy", "run"}
arr[] = {'e','o','b', 'a','m','g', 'l'}
Output : go, me, goal.
Asked In : Microsoft Interview
The idea is to use Trie data structure to store dictionary, then search words in Trie using characters of given array.
Below is the implementation of above idea
go goal me
Time Complexity: O(SIZE^L * N) where L is the length of the longest word in the dictionary and N is the length of the input array.
Auxiliary Space: O(SIZE^L)