Dsa
Monotonic Stack
Easy
Stock Price Drop Duration
You are given the daily closing prices of a stock for a series of days. For each day, calculate how many days it takes until the stock price drops below the current day's price. If the price never drops, return 0. Your program should read the number of days and then the stock prices, and for each day, print the drop duration.
Input format:
The first line contains a single integer, n (1 <= n <= 100000), the number of days.
The second line contains n integers representing the stock prices for each day, where each price is between 1 and 100000.
Output format:
Print n integers as space-separated values, where each integer is the number of days until the price drops below that day's price.
Example:
Input:
5
100 80 60 90 110
Output:
0 1 1 1 0
Key concepts
monotonic_stackarraystock_price
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