Trains the technique from
LeetCode 2762Continuous SubarraysThis 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 log holds the readings readings. A stretch of neighbouring readings is steady when its largest reading and its smallest differ by at most 2. A stretch of one reading is always steady.
Return how many steady stretches the log holds.
Example 1
The three single readings are steady, and so are the two neighbouring pairs, each spread exactly two. The whole log spreads four, so it is not.
Example 2
Every reading is the same, so every stretch has no spread at all and all six count.
Example 3
The two readings spread nine, so only the two single readings are steady.
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 continuous_subarrays(readings: list[int]) -> int:public long continuousSubarrays(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.