Top k frequent items

Write codeHard35 minAmazon and Google style

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) -> list
Example 1
Inputtop_k_frequent(["a", "b", "a", "c", "b", "a"], 2)
Output[["a", 3], ["b", 2]]