#962
Maximum Width Ramp
specialist · 775 · lc medium +31 · verified · 55.9% accepted · 2,841 likes · top 49%
Description
In integer array nums, a ramp (i, j) satisfies i < j and nums[i] <= nums[j], with width j - i. Return the maximum possible ramp width, or 0 if the array contains no valid ramp.
Example 1:
Input: nums = [6,0,8,2,1,5]
Output: 4
Explanation: The maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.
Example 2:
Input: nums = [9,8,1,0,1,9,4,0,4,1]
Output: 7
Explanation: The maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.
Code
1
2
3