Trains the technique from
LeetCode 164Maximum GapThis 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 logger dumps nums, a batch of meter readings in the order they were captured, so the batch is in no particular order and readings may repeat.
Imagine the batch laid out on a number line from smallest to largest. Between each neighbouring pair of that laid-out sequence there is a step, and the step is the difference between the two values. Return the width of the widest step. When the batch holds fewer than two readings there is no step at all, so return 0.
Solve it in time that grows linearly with the number of readings, using extra space that also grows only linearly.
Example 1
Laid out the readings run 3, 7, 20, 41, so the steps are 4, 13 and 21 and the widest is 21.
Example 2
Laid out the readings run 1, 7, 7, giving steps of 6 and 0, so the widest step is 6.
Example 3
A single reading leaves no neighbouring pair, so the answer is 0.
Example 4
All three readings match, so every step is 0.
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 widest_reading_step(readings: list[int]) -> int:public int widestReadingStep(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.