Skip to content

Practice Maximum Width Ramp

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#962
LeetCode Problem

Maximum Width Ramp

Problem Statement

A ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i. Given an integer array nums, return the maximum width of a ramp in nums. If there is no ramp in nums, return 0.

Source: Maximum Width Ramp on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [6,0,8,2,1,5]
Output
4

# Example 2

Input
nums = [9,8,1,0,1,9,4,0,4,1]
Output
7

Constraints

2 <= nums.length <= 5 * 10^4
0 <= nums[i] <= 5 * 10^4

Related LeetCode Problems

Practice more problems similar to Maximum Width Ramp.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.