diff --git a/solutions/day10/solution.cpp b/solutions/day09/solution.cpp similarity index 93% rename from solutions/day10/solution.cpp rename to solutions/day09/solution.cpp index 31bc107..d583855 100644 --- a/solutions/day10/solution.cpp +++ b/solutions/day09/solution.cpp @@ -14,4 +14,4 @@ class Solution { return c+b; } }; -// TC : O(N) SC : O(1) \ No newline at end of file +// TC : O(N) SC : O(1) diff --git a/solutions/day10/maxWidthRamp.cpp b/solutions/day10/maxWidthRamp.cpp new file mode 100644 index 0000000..3a7488e --- /dev/null +++ b/solutions/day10/maxWidthRamp.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + int maxWidthRamp(vector& nums) + { + stack s; + for(int i=0;inums[i]) + s.push(i); + } + int ma = 0; + for(int i=nums.size()-1;i>0;i--) + { + while(!s.empty() && nums[s.top()]<=nums[i]) + { + ma = max(ma,i-s.top()); + s.pop(); + } + } + return ma; + } +};