Algobase
Problems
Get Premium
Pricing
Problems
/
276. Online Stock Span
Prev
Next
Visualizer
Problem
Solution
Code
Mixed Prices
Decreasing Prices
Increasing Prices
⌥
Visualizer will appear here
Problem
Solution
Code
1
class StockSpanner:
2
def __init__(self):
3
self.stack = []
4
def next(self, price):
5
span = 1
6
while self.stack and self.stack[-1][0] <= price:
7
span += self.stack.pop()[1]
8
self.stack.append((price, span))
9
return span
Visualizer
Mixed Prices
Decreasing Prices
Increasing Prices
⌥
Visualizer will appear here