mediumTriesGoogleAmazonMicrosoft
Lexicon Lattice
A keyboard autocomplete routine ingests a dictionary and later answers whole-word and prefix lookups in O(length).
Design a prefix tree that supports insert(word), search(word) (exact), and startsWith(prefix).
Choose approach
·
1/7
Narrationstep 1 of 7
Start with just the root sentinel node.
Variables
ops=6
How to think about it
- Trie branches off per character — shared prefixes share nodes.
- `isEnd` distinguishes search (needs terminator) from startsWith (any node reached).
- Every operation is O(length of query).
Edge cases to catch in interview
- Empty string: root node reached, treat as terminator present.
- Case sensitivity: assume lowercase a-z unless stated otherwise.
Examples
Example 1
[true]{"ops":[{"op":"insert","word":"car"},{"op":"search","word":"car"}]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed