We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4f2d700 commit 2279723Copy full SHA for 2279723
962. Maximum Width Ramp
@@ -0,0 +1,22 @@
1
+class Solution {
2
+public:
3
+ int maxWidthRamp(vector<int>& nums) {
4
+ //decreasing stack
5
+
6
+ int n = nums.size();
7
+ stack<int> st;
8
+ for(int i = 0; i < n; i++){
9
+ if(st.empty() || nums[st.top()] > nums[i]){
10
+ st.push(i);
11
+ }
12
13
+ int ans = 0;
14
+ for(int i = n-1; i > 0; i--){
15
+ while(!st.empty() && nums[st.top()] <= nums[i]){
16
+ ans = max(ans, i - st.top());
17
+ st.pop();
18
19
20
+ return ans;
21
22
+};
0 commit comments