nikunjsoni

901

Mar 24th, 2021
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class StockSpanner {
  2.     stack<pair<int, int> > s;
  3. public:
  4.     StockSpanner() {
  5.        
  6.     }
  7.    
  8.     int next(int price) {
  9.         int res = 1;
  10.         while(!s.empty() && s.top().first <= price){
  11.             res += s.top().second;
  12.             s.pop();
  13.         }
  14.         s.push(make_pair(price, res));
  15.         return res;
  16.     }
  17. };
  18.  
  19. /**
  20.  * Your StockSpanner object will be instantiated and called as such:
  21.  * StockSpanner* obj = new StockSpanner();
  22.  * int param_1 = obj->next(price);
  23.  */
RAW Paste Data