Problem 70 of 75
Implement Trie (Prefix Tree)
The problem
Implement the Trie class: insert(word) stores a word; search(word) returns true if word was inserted; startsWith(prefix) returns true if any inserted word has the given prefix.
insert("apple"); search("apple")=true; search("app")=false; startsWith("app")=true
Your solution runs against 1 unit tests, including edge and large-value cases.
Loading...
Test console · 1 unit tests
Submit your code to run it against all 1 unit tests. Results appear here.
JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.
Hint
Reference solution
Video explanation
GO DEEPER
The full interview treatment: the conversation, why the approach works, and step-by-step visuals.