Grokking Coding Mock Interview
Ask Author
Back to course home

0% completed

Vote For New Content

Solution: Top K Frequent Words
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an array of strings words and an integer k, return the k most frequent strings.

The answer should be sorted by the frequency of the words from highest to lowest. If multiple words have the same frequency, sort them in lexicographical order.

Examples

Example 1

  • Input: words = ["apple", "banana", "apple", "orange", "banana", "apple"], k = 2
  • Expected Output: ["apple", "banana"]
  • Justification: "apple" appears 3 times, "banana" appears 2 times, and "orange" appears once

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible