16 trie interview questions, asked at Amazon, Google, Snowflake and 8 more companies. Last asked Oct 2026.
+1
URL router with single-segment wildcardsCodingBuild a small URL router. - A pattern and a path are split on / into segments. Empty segments are ignored, so /a/b/ is the same as /a/b, and / is the empty path. - A p
Last asked Oct 2026
+3
Word search with a word search II follow-upCodingFind words on a letter grid by adjacent moves, then extend the solution to finding many words at once efficiently. Reported on 1point3acres' Glean bank; reconstructed in our own…
Last asked Sep 2026
+2
Greedy longest-match tokenizerCodingImplement a greedy longest-match tokenizer. You are given a string text and a list dictionary. Each entry has the form "<key:<id". key is a non-empty token string and id is its…
Last asked Sep 2026
Return every word that starts with a prefixCodingBuild a structure over a word list, once, that answers many prefix queries: for a prefix, return every word in the list that starts with it, without rescanning the whole list. A…
Last asked Sep 2026
Highlight categorized phrases in a reviewCodingReviews on a travel site should show key phrases with their category. Write a function that marks every mapped phrase in a review. mapping is a list of (phrase, category) pairs…
Last asked Sep 2026
Trie with insert, search and prefix lookupCodingBuild a trie over a dictionary of words. Support inserting a word, checking whether an exact word is present, and returning every word that starts with a typed prefix, as an…
Last asked Jul 2026
Shortest unique prefix for each wordCodingGiven a list of distinct words, return for each word its shortest unique prefix: the shortest leading substring of the word that no other word in the list starts with. Return the…
Last asked Jun 2026
Store name autocompleteCodingImplement autocomplete over a set of store names: given the prefix typed so far, return the matching stores. Discuss a trie against simpler options, how many results to return and…
Last asked May 2026
Radix cache for integer sequences with LRU evictionCodingImplement RadixCache, a cache of integer sequences (for example, token IDs of model prompts) stored in a radix tree: a trie whose edges hold runs of integers instead of single…
Last asked Jan 2026
+1
Bracket the first matching substring in each wordCodingImplement wrapsubstrings(s: str, elements: liststr) - str. s is a sentence of words separated by single spaces. elements is a list of strings. For each word in s, find the first…
Last asked Jan 2026
Autocomplete with top-k suggestionsCodingGiven a list of past queries with their counts, build an autocomplete: for a prefix the user has typed, return the k most popular completions. Use a trie, and discuss storing top…
Last asked Sep 2025
Implement a trie (prefix tree)CodingImplement a prefix tree over strings: insert a word, check whether a whole word is present, and check whether any stored word starts with a given prefix. Design the classes so…
Last asked Aug 2025
Predictive text for a phone keypadCodingOn a phone keypad each digit maps to several letters (2 = abc, 3 = def, ...). Given a dictionary and a sequence of digit presses, return the words the sequence could spell, T9…
Last asked Jun 2025
Key-value store with prefix searchCodingBuild an in-memory key-value store whose values can also be looked up by key prefix. Keys are strings and values are integers. Implement the KVStore class: - KVStore() creates an…
IP routing table with longest prefix matchCodingBuild the forwarding table of an IPv4 router. Routes are CIDR prefixes mapped to a next-hop name. When a packet arrives, the router must send it to the next hop of the most…
Detect disguised abusive words in commentsCodingA comment platform wants to catch abusive words that users disguise with look-alike characters, such as $ for s or 0 for o. Implement AbuseDetector: - AbuseDetector(banned…