online stock span
https://leetcode.com/problems/online-stock-span/solution/
Official answer:
1class StockSpanner(object):
2 def __init__(self):
3 self.stack = []
4
5 def next(self, price):
6 weight = 1
7 while self.stack and self.stack[-1][0] <= price:
8 weight += self.stack.pop()[1]
9 self.stack.append((price, weight))
10 return weight