Problem, as an interviewer would state it:
"Implement a Trie (prefix tree) with insert(word) and autocomplete(prefix), returning every real inserted word that starts with the given prefix."
Examples:
trie.insert("cat"); trie.insert("car"); trie.insert("card");
trie.autocomplete("ca"); // ["car", "card", "cat"]
Clarifying questions expected:
- Should autocomplete results be returned in a specific order (like alphabetical), or is any order acceptable?
- Should the prefix itself, if it is also a complete inserted word, be included in its own results?
- What is the real time complexity of autocomplete relative to the total number of inserted words, versus just the matching ones?
Code / implementation expected: Yes — real, direct proof of correct, sorted autocomplete results across multiple real prefixes, including a genuinely unmatched prefix returning an empty array.