You are given an array of strings words and an integer k.
Your task is to identify and return the k most frequent words from the input array.
Note that:
Return the k most frequent words.
words = ["apple", "banana", "apple", "cherry", "banana", "apple"]
k = 2
["apple", "banana"]
apple appears 3 times, banana appears 2 times, and cherry appears once. The top 2 frequent words are apple and banana.
words = ["dog", "cat", "dog", "bird", "cat", "dog"]
k = 2
["dog", "cat"]
dog appears 3 times, cat appears 2 times, and bird appears once. The top 2 frequent words are dog and cat.
words = ["apple", "banana", "apple", "cherry", "banana", "apple"]
k = 2
["apple", "banana"]