Autocomplete Pickup Addresses Ranked by Past Ride Popularity
Last updated: November 29, 2026
Quick Overview
Build a structure where record(address) counts one more ride to that address and suggest(prefix) returns up to three addresses starting with prefix, ordered by ride count descending and then alphabetically.
Uber
November 29, 20260
0
0 solved
Build a structure where record(address) counts one more ride to that address and suggest(prefix) returns up to three addresses starting with prefix, ordered by ride count descending and then alphabetically.
Uber onsite loops use this to connect tries to the destination search box in the rider app. Interviewers look for precomputed top results per trie node so suggestions are fast while typing.
What the Interviewer Expects
- Builds a trie keyed by characters of the address
- Stores a small top-3 list at each node along the inserted path
- Updates the lists correctly when an existing address's count rises
- Applies the tie-break on equal counts
- Discusses memory versus query latency trade-offs
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 support personalized suggestions per rider?
- How do you handle typos in the prefix?
- How would you shard this for every city in the world?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
record(address): increment its count (insert if new).suggest(prefix): up to 3 addresses with that prefix, by count desc then lexicographic.- Suggest is called on every keystroke, so it must ...
High-Level Design
Each trie node keeps top, a list of at most 3 addresses that rank highest among all addresses in its subtree. On record, bump the global count, then walk the address's path and at each node merge ...