Dsa
Monotonic Stack
Medium
Stock Price Prediction
You are given a list of stock prices over N days. Each day, the price can either go up or down. Your task is to compute an array where each element at index i represents the number of consecutive days before day i that had a price lower than day i's price. For the first day, the value will always be zero.
Input Format:
- A single line with N (1 <= N <= 100,000) followed by N integers representing the stock prices.
Output Format:
- A single line with N integers representing the number of days until a higher stock price for each day.
Example:
Input:
6 100 80 60 70 60 75 85
Output:
0 0 0 2 0 4 5
Key concepts
monotonic_stackarraysstock_prices
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