Trains the technique from
LeetCode 962Maximum Width RampThis 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.
Readings are given as nums.
A span is a pair of positions i before j where the later reading is at least the earlier one. Its width is the difference of the positions.
Return the widest span, or 0 when no span exists.
Example 1
The reading 14 at the front pairs with the 41 at the end, five apart, which is as wide as the list allows.
Example 2
Every reading falls below the one before it, so no pair qualifies.
Example 3
Equal readings count, since the later one only has to be at least the earlier, so the two ends pair up.
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 max_width_ramp(nums: list[int]) -> int:public int maxWidthRamp(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.