Return the k most frequent tokens with their counts. Tokens with equal counts are ordered by their first appearance in the input. k must be non-negative.
Implement solve(tokens, k).
Returns. Return a list of (token, count) tuples of length at most k, from most to least frequent.
Example 1
Input:
solve(['a', 'b', 'a', 'c', 'b', 'a'], 2)
Output:
[('a', 3), ('b', 2)]
Example 2
Input:
solve(['x', 'y', 'x', 'y', 'z'], 3)
Output:
[('x', 2), ('y', 2), ('z', 1)]
No results yet
Run your code to check it against the examples, or submit to run every test.