Design an autocomplete data structure using a trie.
You must support:
insert(word: string) -> void
search(word: string) -> bool
(exact match)
startsWith(prefix: string) -> bool
suggest(prefix: string, limit: int) -> list[string]
returning up to
limit
words that start with
prefix
.
a-z
.
suggest
may return results in any deterministic order (e.g., lexicographic) as long as it is consistent.
suggest
should be proportional to output size (plus traversal).