Mental Model
We want to find the K numbers that appear most often in a list by counting frequencies and using a special structure to keep track of the top counts.
Analogy: Imagine you have a bag of colored balls and you want to find the top K colors that appear most. You count how many balls of each color you have, then keep only the top K counts on a scoreboard that quickly shows the smallest count on top so you can replace it if a bigger count comes.
Input array: [1, 1, 1, 2, 2, 3]
Frequency map: {1:3, 2:2, 3:1}
Min-heap (size K=2):
2 (freq 2)
/
1(freq 3)
Top K frequent elements: [2, 1]