A ramp in an integer array `nums` is a pair `(i, j)` with `i < j` and `nums[i] <= nums[j]`. Its width is `j - i`. Return the maximum width of a ramp in `nums`, or 0 if there is no ramp.
A ramp in an integer array nums is a pair (i, j) with i < j and nums[i] <= nums[j]. Its width is j - i. Return the maximum width of a ramp in nums, or 0 if there is no ramp.
Example 1:
Input: {"nums":[6,0,8,2,1,5]}
Output: 4
Constraints:
2 <= nums.length <= 5 * 10^4
0 <= nums[i] <= 5 * 10^4
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[6,0,8,2,1,5]}
A good left end for a ramp is a value lower than everything before it, so the first pass keeps a stack of those "new minimum" indices.