The Finding MK Average interview question is a high-level design task for a data stream. You need to implement a structure that stores the last numbers. When a query is made, you must:
Google and Amazon ask the Finding MK Average coding problem to test a candidate's ability to maintain a Sorted Sliding Window. It requires balancing three different sorted sets (Smallest, Middle, Largest) while handling deletions of elements that are no longer in the last positions. It evaluations your mastery of Ordered Set interview patterns.
This problem is solved using Three Sorted Sets (or balanced BSTs) and a Queue.
low (size ), mid (size ), and high (size ).sumMid to track the sum of elements in the mid set for average calculation.low < mid < high.. Stream: [10, 20, 30, 40, 50, 60]
low: {10}, mid: {20, 30, 40, 50}, high: {60}.sumMid = 140. Average = .low: {5}, mid: {20, 30, 40, 50}, high: {60}.sumMid when an element moves between sets during rebalancing.Master the use of MultiSets (C++) or multiple TreeMaps (Java). They are essential for sliding window problems where you need to track ranked statistics like the median or MK-average in time.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Sequentially Ordinal Rank Tracker | Hard | Solve | |
| Design an Array Statistics Tracker | Hard | Solve | |
| Stock Price Fluctuation | Medium | Solve | |
| Exam Room | Medium | Solve | |
| Number of Recent Calls | Easy | Solve |