This is the kind of question where the basic idea clicks fast but the details wreck you.
Clarify the median definition for even k, then propose a sliding window with two heaps (max-heap for lower half, min-heap for upper half) to maintain the median in O(log k) per element. Discuss how to handle deletions using lazy deletion or indexed heaps, and analyze time and space complexity.
Pro tip: Explicitly state the median convention for even k (e.g., average of two middle elements) and mention that lazy deletion can cause heap size drift, so periodic cleanup or a balanced approach is needed to keep operations O(log k).
Define median for even k (e.g., average of two middle values) and discuss handling duplicates, deletions, and edge cases like k > n or k = 1.
Select two heaps (max-heap for lower half, min-heap for upper half) to maintain the median, and decide on a deletion strategy (lazy deletion with counters or indexed heaps).
Initialize the heaps with the first k elements, balance them, compute the median, then slide the window by adding the new element and removing the old one, rebalancing after each operation.
Explain that each insertion and deletion takes O(log k) time, leading to O(n log k) total time, and that space is O(k) for the heaps and any auxiliary structures.
Mention alternative approaches like order-statistic trees or Fenwick trees, and compare their complexity and implementation difficulty to the two-heap method.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.