2
from collections import defaultdict6
def medianSlidingWindow(self, nums: List[int], k: int) -> List[float]:12
if len(lo) == len(hi):13
heapq.heappush(hi, -heapq.heappushpop(lo, -nums[i]))15
heapq.heappush(lo, -heapq.heappushpop(hi, nums[i]))16
ans = [float(hi[0])] if k & 1 else [(hi[0] - lo[0]) / 2.0]17
to_remove = defaultdict(int)18
for i in range(k, len(nums)): # right bound of window19
heapq.heappush(lo, -heapq.heappushpop(hi, nums[i])) # always push to lo22
heapq.heappush(hi, -heapq.heappop(lo))23
to_remove[out_num] += 124
while lo and to_remove[-lo[0]]:25
to_remove[-lo[0]] -= 127
while to_remove[hi[0]]:31
ans.append(float(hi[0]))33
ans.append((hi[0] - lo[0]) / 2.0)