Top k frequent items
Your task
Given a stream of string items, return the k most frequent items. Order the result by frequency descending; break ties by the item string ascending (lexicographic). Return a list of [item, count] pairs of length min(k, number of distinct items). If k <= 0 return an empty list. The stream may be empty.
Examples
top_k_frequent(items: list[str], k: int) -> listExample 1
Input
top_k_frequent(["a", "b", "a", "c", "b", "a"], 2)Output
[["a", 3], ["b", 2]]