Loading...
Loading...
Loading...
A search box stores n words. For a typed prefix, print up to 3 different stored words that start with it, in alphabetical order, one per line. If no word starts with the prefix, print NONE. A word stored more than once is listed once.
Example 1
Input
7 tea ten tent tend to tea zoo te
Output
tea ten tend
The distinct matches are tea, ten, tend and tent. The first three alphabetically are shown.
Example 2
Input
1 ab b
Output
NONE
Try the problem first. Open one hint at a time.
Build a trie and walk to the node for the prefix.
Search below it in letter order and stop once three words are found.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor