Autocomplete top 3
Your task
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.
Examples
autocomplete(words: list[list], queries: list[str]) -> list[list[str]]Example 1
Input
autocomplete([["cat", 5], ["car", 9], ["card", 2], ["dog", 7]], ["ca", "do", "x"])Output
[["car", "cat", "card"], ["dog"], []]