Preparing your design workspace

Loading the problem and your saved attempt…

Design and Implement a Trie Search Index

Model a mutable in-memory term index with exact lookup and deterministic prefix search.

For this exercise, assume an in-memory search index stores unique lowercase terms. Each term has a string payload ID and a nonnegative popularity score. The index supports adding a new term, updating an existing term's payload or score, removing a term, exact lookup, and prefix search.

Prefix search accepts 0 <= k <= 100 and returns at most k active terms ordered by descending score and then lexicographically; an empty prefix may match all terms, and k = 0 returns an empty list. Use a trie as the primary search structure.

Duplicate add, unknown update or removal, invalid characters, negative scores, and k outside the supported range produce distinguishable failures, and failed operations leave state unchanged. Design the objects, responsibilities, interfaces, and interactions, then implement trie insertion and prefix search.

Tokenization, document crawling, ranking models, persistence, distributed sharding, fuzzy matching, and access control are outside scope.