Ranked Typeahead for Member Names With Prefix Suggestions
Last updated: November 29, 2026
Quick Overview
Design a class that stores member names with a popularity score and, given a prefix, returns the top 3 names by score (ties broken alphabetically). Support inserting new names and updating scores.
0
0
0 solved
Design a class that stores member names with a popularity score and, given a prefix, returns the top 3 names by score (ties broken alphabetically). Support inserting new names and updating scores.
LinkedIn's global search bar suggests people as you type. The coding version checks trie construction, how you keep per-prefix top results cheap, and how you reason about the update versus query trade-off.
What the Interviewer Expects
- Builds a trie keyed by lowercase characters
- Discusses storing top-k at each node versus collecting the subtree at query time
- Handles score updates correctly, including names moving out of a node's top list
- Orders results by score descending then name
- Analyzes memory as total characters times k
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 personalize suggestions by the searcher's network?
- How do you shard this typeahead across servers?
- How would you handle typos, such as 'jhon' for 'john'?
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: add(name, score) inserts or overwrites the score, and suggest(prefix) returns up to 3 names. Matching is case-insensitive on the prefix; results return the original names. Names are un...
High-Level Design
Use a trie where each node keeps a small cached list of the best names under it. On add, walk the path and, at each node, update that node's candidate list: remove the name if present, insert with t...