Code Room
CodingMediumcod-g594
Subject StacksLevel Mid–Senior~20 minCommon in Distributed systems · Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.