Code Room
CodingHardcod-g577
Subject HeapsLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

Given an integer array nums and a window size k, return the median of each sliding window of size k, doubled and cast to int (i.e. return int(2*median) to avoid float ambiguity). The median of an even-sized window is the average of the two middle elements. Use two heaps with lazy deletion so each step is O(log k). 1 <= k <= len(nums) <= 10^5. Return a list of length len(nums) - k + 1.

Implement
window_median2x(nums: list[int], k: int) → list[int]
Examples
in[[1,3,-1,-3,5,3,6,7],3]out[2,-2,-2,6,10,12]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.