Online Stock Span

Medium · Stack & Monotonic Stack · about 20 minutes

Asked at Amazon, Bloomberg, Coinbase, Citadel, Revolut, Kraken.

Design a class that receives daily stock prices one at a time. next(price) returns the span for today: the number of consecutive days, ending today and going backwards, on which the price was less than or equal to today's price.

Related guides