Autocomplete Destination Names Ranked by Search Volume
Last updated: November 29, 2026
Quick Overview
Build a structure that records destination searches with counts and, given a typed prefix, returns the top k destination names by search volume (ties broken alphabetically). Suggestions must be fast because they run on every keystroke.
Airbnb
November 29, 20260
0
0 solved
Build a structure that records destination searches with counts and, given a typed prefix, returns the top k destination names by search volume (ties broken alphabetically). Suggestions must be fast because they run on every keystroke.
The Airbnb search bar suggests destinations as guests type 'Pa' for Paris or Palm Springs, and latency on each keystroke matters more than write speed. The interviewer wants a trie, a clear decision about where to pay the cost of ranking, and awareness of memory trade-offs.
What the Interviewer Expects
- Choose a trie keyed by characters, normalized to lowercase
- Cache the top k at each node so queries are O(prefix length)
- Update caches along the path when volume changes
- Define a deterministic tie-break
- Discuss memory cost of caching and alternatives
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you handle volumes that decrease or decay over time?
- How would you support typo tolerance, for example 'Prais'?
- How would you serve this across many regions and languages?
- When would you instead compute top k at query time with a DFS?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Operations: record(name, searches) adds volume, and suggest(prefix) returns up to k names with that prefix, ordered by volume descending and then name. Matching is case-insensitive. Reads vastly o...
High-Level Design
Use a trie. At every node, keep a small sorted list of the best k names in that subtree. A query walks the prefix and returns the cached list, so it is O(len(prefix) + k). On record, walk the name's...