Autocomplete
Medium · Data Structures
Finish the Autocomplete class that powers a search box. Store the words however you like (a sorted array, an object, a prefix tree...).
- insert(word) stores a lowercase word. Inserting the same word twice stores it once.
- suggest(prefix, limit) returns the stored words that start with prefix, sorted alphabetically, at most limit of them. A word equal to the prefix counts. The empty prefix matches every word.
The function runAutocomplete is already written: it inserts all words, then answers each [prefix, limit] query.
Next: Merge Intervals