Dsa
Monotonic Stack
Easy
Stock Price Spanner
You are given the price of a stock over n days. For each day, calculate how many consecutive days (including today) the stock price has been less than or equal to today’s price. You need to return an array of the calculated spans.
Input Format:
- A single line containing n integers, representing the stock prices, separated by spaces.
Output Format:
- A single line containing n integers, representing the spans, separated by spaces.
Example:
Input:
100 80 60 70 60 75 85
Output:
1 1 1 2 1 4 6
Key concepts
monotonic_stackfinancearrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now