From bde91e25d565e83308a62aaaed497bac957a07e4 Mon Sep 17 00:00:00 2001 From: vidhirohira <159313286+vidhirohira@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:29:16 +0530 Subject: [PATCH] Created 10-10-2024 POTD This consists of solution to leetcode problem of the day - 10-10-2024 --- october_2024/10-10-2024 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 october_2024/10-10-2024 diff --git a/october_2024/10-10-2024 b/october_2024/10-10-2024 new file mode 100644 index 0000000..ffaf34c --- /dev/null +++ b/october_2024/10-10-2024 @@ -0,0 +1,21 @@ +class Solution { +public: + int maxWidthRamp(vector& nums) + { + int n = nums.size(); + stack 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; + } +};