Skip to content

Commit

Permalink
Merge pull request #65 from horrible-hacker/main
Browse files Browse the repository at this point in the history
Added POTD solution of 10th october
  • Loading branch information
arya2004 authored Oct 11, 2024
2 parents a687d6c + 57f485a commit 493902b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class Solution {
return c+b;
}
};
// TC : O(N) SC : O(1)
// TC : O(N) SC : O(1)
24 changes: 24 additions & 0 deletions solutions/day10/maxWidthRamp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
int maxWidthRamp(vector<int>& nums)
{
stack<int> s;
for(int i=0;i<nums.size();i++)
{
if(i==0)
s.push(i);
else if(nums[s.top()]>nums[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;
}
};

0 comments on commit 493902b

Please sign in to comment.