Leetcode 692. Top K Frequent Words
Count word frequencies and return the k most frequent words sorted by descending frequency, breaking ties by lexicographical order. The core challenge is combining frequency counting with an efficient top-k selection (e.g., hash map plus a min-heap or partial sort) to meet the O(n log k) time / O(n) space follow-up.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early August, 2026
Given a list of log messages, return the Top K most frequent logs. input: logs = [ "Error axios", "This is error", "Error axios", "Database timeout", "This is error", "Error axios" ] print(top_k_frequent_logs(logs, 2)) Output: ['Error axios', 'This is error']
Mid March, 2026
- Given a parse log with user id, time stamp and query find top k queries. - What if this doesn't fit in memory
Hello Interview Premium
Your account is free and you can post anonymously if you choose.