BBox·DSASDE-2Technical Phone Screen
Top K Frequent Words
Problem
Given a list of words, return the k most frequent, sorted by frequency then lexicographically.
Example
["i","love","leetcode","i","love","coding"], k=2 -> ["i","love"]
Constraints
- 1 ≤ words.length ≤ 10^4
Approach
Count map + heap with custom comparator. Reported Box question.
added 6 days ago