Count first: Counter for frequencies, O(n).
Select Top K: Maintain a min-heap of size K keyed by frequency - O(n log K) overall. Or sort all unique elements O(m log m), where m is the number of distinct elements. State complexity and tradeoffs proactively.
Faster option: Bucket sort by frequency in O(n). Pull this out when the follow-up pushes for linear time.
Python pitfalls: heapq compares tuples, so make sure ties never reach uncomparable objects. nlargest is a one-liner, but be ready to hand-write the heap version.
Get asked follow-ups live, then receive a scored report — like a real MLE interview loop.
Start AI mock interview