The Most Frequent IDs problem gives you a sequence of events where each event adds or removes an ID from a collection. After each event, report the ID that has appeared most frequently so far. This Most Frequent IDs coding problem requires maintaining a dynamic frequency count with an efficient maximum query. The combination of a hash map and a max-heap or ordered set is the natural solution.
Amazon and Bloomberg ask this to test real-time frequency tracking with efficient maximum retrieval. It validates knowledge of ordered data structures (heaps or TreeMap) for maintaining a dynamic maximum. The array, hash table, ordered set, and heap interview pattern is the core, and the challenge of handling deletions and lazy updates makes this more nuanced than standard frequency problems.
Hash map + max-heap with lazy deletion. Maintain freq[id] = current frequency of each ID. Use a max-heap of (frequency, id) pairs. When frequency updates, push the new (freq, id) to the heap. When querying max, pop from the heap until the top entry matches the current frequency in the hash map (lazy deletion of stale entries). Return the current max ID.
Events: [("add", 1), ("add", 2), ("add", 1), ("remove", 2), ("add", 3)].
Dynamic maximum problems where frequencies change require lazy deletion heaps. The pattern: push updates to the heap without removing old entries; when querying, skip stale entries (where heap top doesn't match current hash map value). Practice lazy deletion on heaps — it's the most common heap optimization technique in dynamic frequency problems and appears frequently in streaming data interview questions at Bloomberg and Amazon.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| The Number of the Smallest Unoccupied Chair | Medium | Solve | |
| Design Movie Rental System | Hard | Solve | |
| Design a Food Rating System | Medium | Solve | |
| Design a 3D Binary Matrix with Efficient Layer Tracking | Medium | Solve | |
| Design Task Manager | Medium | Solve |