Code Room
CodingHardcod-g767
Subject TrieLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

Build an autocomplete index from a list of (word, frequency) pairs. Then for each query prefix, return up to 3 completions that start with that prefix, ranked by frequency descending; break ties by lexicographic order of the word ascending. Process the queries in order and return a list of result lists (each a list of words). A query with no matching word yields an empty list.

Implement
autocomplete(words: list[list], queries: list[str]) → list[list[str]]
Examples
in[[["cat",5],["car",9],["card",2],["dog",7]],["ca","do","x"]]out[["car","cat","card"],["dog"],[]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.