Top Words
150 points · 0 solved
The first line is k. Everything after it is text (any number of lines). A word is a maximal run of ASCII letters A–Z/a–z; compare words case-insensitively and print them in lowercase.
Print the k most frequent words as word count, sorted by count (highest first), breaking ties alphabetically. If there are fewer than k distinct words, print them all.
Example 1 input
2 The cat and the hat. The end!
Expected output
the 3 and 1
main.py
Ctrl+Enter runs · Ctrl+Shift+Enter submits