962. Maximum Width Ramp Medium

@problem@discussion
#Array#Stack#Monotonic Stack



1/**
2 * [962] Maximum Width Ramp
3 *
4 * 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.
5 * Given an integer array nums, return the maximum width of a ramp in nums. If there is no ramp in nums, return 0.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [6,0,8,2,1,5]
10 * Output: 4
11 * Explanation: The maximum width ramp is achieved at (i, j) = (1, 5): nums[1] = 0 and nums[5] = 5.
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [9,8,1,0,1,9,4,0,4,1]
16 * Output: 7
17 * Explanation: The maximum width ramp is achieved at (i, j) = (2, 9): nums[2] = 1 and nums[9] = 1.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	2 <= nums.length <= 5 * 10^4
23 * 	0 <= nums[i] <= 5 * 10^4
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/maximum-width-ramp/
29// discuss: https://leetcode.com/problems/maximum-width-ramp/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn max_width_ramp(nums: Vec<i32>) -> i32 {
35        0
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_962() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.