Skip to content

Commit

Permalink
Solution to #19
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatr21 committed May 19, 2020
1 parent 447691c commit 2af5b84
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Solutions/S19.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class StockSpanner {
public:
stack<pair<int, int>> st;
StockSpanner() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}

int next(int price) {
int span = 1;
while(!st.empty() && st.top().first <= price) {
span += st.top().second;
st.pop();
}
st.push({price, span});
return span;
}
};

0 comments on commit 2af5b84

Please sign in to comment.