Autocomplete Merchant Names Ranked by Search Frequency
Last updated: November 29, 2026
Quick Overview
Build a structure that records merchant name searches and returns the three most frequently searched names starting with a given prefix, breaking ties alphabetically.
Capital One
November 29, 20260
0
0 solved
Build a structure that records merchant name searches and returns the three most frequently searched names starting with a given prefix, breaking ties alphabetically.
Capital One Shopping and the transaction search in the Capital One app both suggest merchants as a user types. The screen checks that you choose a trie for prefix lookups, think about where to pay the cost (insert time versus query time), and keep each keystroke fast.
What the Interviewer Expects
- Use a trie keyed by lowercase characters
- Cache the top 3 at each node so queries are O(prefix length)
- Update caches correctly when a name's count increases
- Apply the tie-break consistently
- Discuss memory cost of per-node caches
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 typo tolerance, such as 'starbcks'?
- How would you decay old searches so seasonal merchants fade?
- How would you shard this when the merchant list has tens of millions of names?
- What would you cache in the browser versus the server?
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(name)increments a case-insensitive count for that name.suggest(prefix)returns up to 3 lowercase names with that prefix, by count descending then name ascending.- Queries happen on e...
High-Level Design
A trie gives prefix navigation in O(length). Without caching, suggest would have to walk the entire subtree under the prefix, which for 'S' means a big chunk of the catalog. Instead, every node on a...