Mental Model
We want to find the K numbers that appear most often in a list by counting frequencies and keeping only the top K using a special list that quickly gives the smallest frequency.
Analogy: Imagine you have a bag of colored balls and want to keep only the K colors you see most often. You count how many balls of each color you have, then keep a small box that always holds the K colors with the most balls, throwing out less frequent colors as you find more frequent ones.
Input list: [1,1,1,2,2,3] Frequency map: 1:3, 2:2, 3:1 Min-heap (size K=2): [ (2,2) ] ↑ root (smallest frequency) After adding (1,3): [ (2,2), (1,3) ] ↑ root We keep only top 2 frequent elements
