Top K Frequent Words

easy
Unit 1 · Binary Search & Heaps0/3 to milestone

Implement top_k_words(words, k) returning the k most frequent words, most frequent first. Break ties alphabetically. Comparison is case-insensitive, so return words in lowercase.

Then implement top_k_heap(words, k) with the same output, using a heap of size k so it runs in O(n log k). (Hint: Python's heapq is a min-heap, so think about what to keep at the top.)

#heaps#hashing#sorting2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Top K Frequent Words · TechGradify