Trains the technique from
LeetCode 1438Longest Continuous Subarray With Absolute Diff Less Than or Equal to LimitThis 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 pipeline crew samples the line pressure once a minute for a whole shift. readings[i] is the gauge value, in kilopascals, taken at minute i, and every gauge value is at least 1.
A run of consecutive minutes counts as steady when the highest and the lowest value recorded anywhere in that run differ by no more than spread. Note that this is judged on the extremes of the whole run, not on how much the gauge moves from one minute to the next.
Return how many minutes long the longest steady run is. A run of one minute has nothing to differ from itself, so the answer is never below 1.
Example 1
Minutes 2 through 4 read 9, 8 and 6, whose extremes differ by exactly 3, so that run of three is steady. No run of four minutes is.
Example 2
A spread of 0 admits only runs where every value is identical, and the longest of those is the opening three minutes.
Example 3
Both neighbouring pairs differ by 6, so no run of two minutes holds, and the answer falls back to a single minute.
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 steady_pressure_span(readings: list[int], spread: int) -> int:public int steadyPressureSpan(int[] readings, int spread)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.