Top K Frequent Elements
Return the K most frequent elements using a frequency map plus min-heap, or bucket sort for O(n) solution.
webcoderspeed.com
7 articles
Return the K most frequent elements using a frequency map plus min-heap, or bucket sort for O(n) solution.
Sort characters in a string by decreasing frequency using a frequency counter and max-heap or bucket sort.
Design a stack that pops the most frequent element, breaking ties by most recently pushed, using frequency-bucket stacks.
Find the minimum intervals to execute all tasks with cooldown n by greedily scheduling the most frequent task first.
Group anagrams, find anagram indices, and count anagram occurrences. Three approaches: sort key O(nk log k), frequency tuple O(nk), and sliding window O(n+k).
Find the k most frequent elements using a max-heap or bucket sort. O(n) bucket sort approach using frequency as bucket index — faster than O(n log n) heap.
Implement an LFU cache with O(1) get and put. Uses two hashmaps and per-frequency doubly linked lists to track access frequency and recency simultaneously.