Loading...
Loading...
Loading...
A blog has n posts, each with one tag. Print the k most frequent tags, most frequent first, as tag count. If two tags occur equally often, the alphabetically smaller tag comes first.
tag count.Example 1
Input
8 2 red blue red green blue red yellow blue
Output
blue 3 red 3
red and blue both appear 3 times, and blue comes first.
Example 2
Input
3 1 a b a
Output
a 2
Try the problem first. Open one hint at a time.
Count the tags with a dictionary or Counter.
Use the key (-count, tag) so the biggest count comes first and ties go alphabetically.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor