Top K Frequent Words

Try to solve the Top K Frequent Words problem.

Statement

Given a string array, words, and an integer k, return the kk most frequent strings.

Sort the frequencies from highest to lowest and then return the top kk frequent words. Words with the same frequency should be sorted by their lexicographical order.

Constraints:

  • 11 \leq words.length 500\leq 500

  • 11 \leq words[i].length 10\leq 10

  • words[i] consists of lowercase English letters.

  • kk is in the range [1, The number of unique words[i]]

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.