Code RoomStock span
MediumPrep Room Coding #1160

Stock span

CodingDistributed systemsAlgorithms & data structuresMid–Senior~20 min

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).

Implement
stock_spanner(prices: list[int]) → list[int]
Examples
in[[100,80,60,70,60,75,85]]out[1,1,1,2,1,4,6]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[[100,80,60,70,60,75,85]][1,1,1,2,1,4,6]not run yetsample