Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 124: Maps: Fundamentals
Implement a prefix tree (trie). Implement `Trie`: - `insert(word)` adds a word. - `search(word)` returns whether the exact word was inserted. - `startsWith(prefix)` returns whether any inserted word starts with prefix.
+ 1 hidden test run on Submit.
A trie stores words character by character; the end flag distinguishes a full word from a prefix. Each operation is O(word length).
Run your code to see results.