Stock span

Write codeMedium20 minBloomberg and Amazon style

Your task

A stock's daily prices arrive one at a time. The span of a price on a given day is the number of consecutive days up to and including that day for which the price was less than or equal to that day's price (counting backwards from today). Given the list of prices in order, return the list of spans, one per day, computed online with a monotonic stack so the whole pass is amortized O(n).

Examples

stock_spanner(prices: list[int]) -> list[int]
Example 1
Inputstock_spanner([100, 80, 60, 70, 60, 75, 85])
Output[1, 1, 1, 2, 1, 4, 6]