184. Top K Frequent Words
MediumHash MapSorting
Print the k most frequent words, most frequent first; ties are broken alphabetically.
Input format
Line 1: n k Line 2: n lowercase words
Output format
k words, space-separated.
Example 1
Input
6 2 i love leetcode i love coding
Output
i love
Example 2
Input
10 4 the day is sunny the the the sunny is is
Output
the is sunny day
Constraints
1 ≤ k ≤ number of distinct words
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…