Write sliding_median(nums: list[int], k: int) -> list[int].
Slide a window of k consecutive elements over nums, left to right. For each window, report its median: the element at position (k + 1) // 2 (1-based) when the window is sorted. So for even k you take the lower of the two middle values. Return the list of len(nums) - k + 1 medians.
Example: nums = [5, 1, 4, 2, 8, 3], k = 3 gives [4, 2, 4, 3]. With k = 4 it gives [2, 2, 3] (e.g. sorted first window [1, 2, 4, 5], 2nd element is 2).
Constraints: 1 <= k <= len(nums) <= 2 * 10^5, 1 <= nums[i] <= 10^9 (duplicates allowed).
Sorting every window is O(n·k log k) and far too slow for the large test. Aim for about O(n log n); keeping the window sorted incrementally (O(k) per step, but with a very small constant) also passes.
Show hint
you need a structure that supports insert, delete and "k-th smallest" quickly. Two heaps split at the median can do it if you delay deletions until a stale value reaches the top.