Trains the technique from
LeetCode 239Sliding Window MaximumThis 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 weather mast logs one temperature per minute for an entire shift. readings[i] is the whole-degree Celsius value captured during minute i; anything below freezing is negative.
The report generator studies blocks of span back-to-back minutes. The first block covers minutes 0 through span - 1. Each following block starts one minute later than the one before it, and the last block is the one whose final minute is the final minute of the shift. For every block the generator keeps a single number: the largest reading anywhere inside that block.
Return those block peaks, listed in the same order the blocks were studied. For n readings and a block of span minutes there are n - span + 1 peaks to report.
span is never smaller than 1 and never larger than the number of readings, so there is always at least one block. When span is 1 each block is a single minute, and when span equals the number of readings there is exactly one block covering the whole shift.
Example 1
Five blocks of three minutes fit in seven readings. The two sixes keep the peak at 6 for the first four blocks, and once both have dropped out of view the last block peaks at 7.
Example 2
Every block is one minute long, so each reading is its own peak and the output copies the input.
Example 3
The block width matches the shift length, so a single block covers all four minutes and its warmest reading is -2 degrees.
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_peaks(readings: list[int], span: int) -> list[int]:public int[] rollingPeaks(int[] readings, int span)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.