Dsa
Monotonic Stack
Medium
Stock Span
You are given the prices of a stock over a series of days. For each day, you want to calculate how many consecutive days before that day the stock price was less than or equal to the price on that day.
Input:
- A single line of space-separated integers representing daily stock prices.
Output:
- A single line of space-separated integers where each integer represents the stock span for that day.
Example:
Input: 100 80 60 70 60 75 85
Output: 1 1 1 2 1 4 6
Key concepts
monotonic_stackstocksarray
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