#K49627. Top K Frequent Words
Top K Frequent Words
Top K Frequent Words
You are given an array of n words and an integer k. Your task is to find the k most frequent words in the array. The answer should be returned in descending order of frequency. In the event that two words have the same frequency, they should be output in lexicographical (alphabetical) order.
Note: The input and output are processed via standard input (stdin) and standard output (stdout), respectively.
Example:
Input: 6 2 i love leetcode i love coding</p>Output: i love
inputFormat
The first line contains two integers n and k, where n is the number of words and k is the number of frequent words to return.
The second line contains n space-separated words.
outputFormat
Output the k most frequent words in one line separated by a single space.
## sample6 2
i love leetcode i love coding
i love