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.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

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
trie
prefix search
top-k caching
typeahead
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported