Skip to content

Commit

Permalink
Created 10-10-2024 POTD
Browse files Browse the repository at this point in the history
This consists of solution to leetcode problem of the day - 10-10-2024
  • Loading branch information
vidhirohira authored Oct 15, 2024
1 parent 4a83fac commit bde91e2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions october_2024/10-10-2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
int maxWidthRamp(vector<int>& nums)
{
int n = nums.size();
stack<int> st;
for(int i = 0; i < n; i++){
if(st.empty() || nums[st.top()] > nums[i]){
st.push(i);
}
}
int ans = 0;
for(int i = n-1; i > 0; i--){
while(!st.empty() && nums[st.top()] <= nums[i]){
ans = max(ans, i - st.top());
st.pop();
}
}
return ans;
}
};

0 comments on commit bde91e2

Please sign in to comment.