Back to problems

Stock Price Tracker (Online Stock Span)

Algorithm · Bloomberg · Medium

You are given an array prices of length n, where prices[i] represents the stock price on the i-th day (0‑indexed, earliest to latest). For each day, you must compute its stock span, defined as the maximum number of consecutive days ending on that day (including the day itself) for which the price is less than or equal to today’s price. Return the spans as an integer array, where the i-th element is the span for day i. The span essentially tells you how many recent days (up…

Checking your access…