✅ Problem Summary
Goal: Given a stream (or array) of integers and an integer k, return the k most
frequent elements.
🧾 Input:
● An integer array stream (or list of elements).
● An integer k, the number of most frequent elements to track.
🎯 Output:
● A list of the k most frequent elements (order can be arbitrary unless stated otherwise).
✅ Example 1:
Input: nums = [1, 1, 1, 2, 2, 3], k = 2
Output: [1, 2]
// 1 appears 3 times, 2 appears 2 times, 3 appears once
✅ Example 2:
Input: nums = [4, 4, 4, 4, 6, 6, 6, 7, 7, 5], k = 3
Output: [4, 6, 7]
// Frequencies: 4 → 4x, 6 → 3x, 7 → 2x, 5 → 1x