Trains the technique from
LeetCode 480Sliding Window MedianThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A monitor logs one integer per tick into readings. A frame of span consecutive readings
starts at the left end and slides right one tick at a time, so the first frame covers
positions 0 through span - 1, the next covers 1 through span, and so on until the
frame reaches the right end.
The middle value of a frame is defined on the frame's readings put in sorted order. When
span is odd it is the single reading in the centre. When span is even it is the mean of
the two central readings, so it can land halfway between two integers and must be reported
that way, for example 5.5.
Return the middle value of every frame, in the order the frames appear.
Example 1
The three frames sort to [1,4,7], [1,1,7] and [1,7,8], and the centre entry of each is 4, 1 and 7.
Example 2
Every frame holds two readings, so each answer is their mean: 4 for 6 and 2, 5.5 for 2 and 9, and 6.5 for 9 and 4.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def rolling_medians(readings: list[int], span: int) -> list[float]:public double[] rollingMedians(int[] readings, int span)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.