Standard Bar Stack and Queues · Implementation O(n) · O(n)
A trading terminal receives one price per tick and must instantly show the retro-scope count: how many consecutive ticks up to and including now have posted a price at or below today's. Yesterday's ticks beyond the last strictly-higher price are irrelevant — the terminal keeps only those survivors on a shortlist.
Input: An integer array prices given in tick order.
Output: Return the span for each tick: the count of consecutive prior days (including itself) with price <= that day's price.
1 <= prices.length <= 10^51 <= prices[i] <= 10^5Spans are computed as a running stream, left to rightInput: {"prices":[100,80,60,70,60,75,85]}
Output: [1,1,1,2,1,4,6]
75 looks back over 60,70,60 (all <=) and stops at 80; 85 additionally covers the 80, reaching 6.
Input: {"prices":[50,50,50]}
Output: [1,2,3]
Equal prices count toward the span, so the run keeps extending.