Mental Model
We find the elements that appear most often by counting them, then keep only the top K using a small container that quickly removes the least frequent.
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 adding colors to a small box that always throws out the color with the fewest balls when full.
Input array: [1,1,1,2,2,3]
Frequency map: {1:3, 2:2, 3:1}
Min-heap (size K=2):
(freq=2, val=2)
(freq=3, val=1)
Top K frequent elements: [1, 2]