Ranked Category Autocomplete For Marketplace Search Box

Last updated: November 29, 2026

Quick Overview

Build a structure that stores marketplace category and search terms with popularity weights and, given a typed prefix, returns the k most popular matching terms, breaking ties alphabetically. Adding an existing term increases its weight.

Whatnot
Coding & Algorithms
Software Engineer
Whatnot
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Build a structure that stores marketplace category and search terms with popularity weights and, given a typed prefix, returns the k most popular matching terms, breaking ties alphabetically. Adding an existing term increases its weight.

Whatnot search spans categories like trading cards, sneakers, comics, and vintage, and the search box suggests popular terms as buyers type. The interviewer wants a trie with a clear ranking rule, and then a discussion of precomputing top k per node for latency.

What the Interviewer Expects
  • Use a trie keyed by characters with weights at terminal nodes
  • Normalize case consistently on insert and lookup
  • Collect matches under the prefix node and rank by weight then name
  • Handle missing prefixes cleanly
  • Propose caching top k per node when reads dominate
Key Topics to Cover
tries
prefix search
top-k ranking
string normalization
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 keep a precomputed top k list at each node up to date as weights change?
  • How would you handle typos in the prefix?
  • How would you personalize suggestions to a buyer's followed categories?
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

add(term, weight) inserts or increments a term. suggest(prefix, k) returns up to k terms starting with the prefix, highest weight first, ties broken alphabetically. Matching is case-insensitive. T...

High-Level Design

Each trie node has a child map and an optional weight that is set when a term ends there. For a query, walk down the prefix, then do a DFS over that subtree collecting (-weight, term) pairs, and tak...


Submit Your Answer
Markdown supported

Related Questions