Mental Model
Find the most common items by counting them, then keep only the top few using a special list that quickly removes the least common.
Analogy: Imagine you have a basket of fruits and want to keep only the top 2 most frequent fruits. You count each fruit, then keep adding fruits to a small box that always throws out the least common fruit when full.
Input array: [1,1,1,2,2,3]
Frequency map: {1:3, 2:2, 3:1}
Min-heap (size k=2):
[2:2]
[1:3]
Heap keeps smallest frequency on top to remove when new bigger frequency comes.