Dsa
Monotonic Stack
Hard
Stock Price Anomaly
You are analyzing a series of stock prices over n days. Your goal is to find the most recent price from a prior day that is higher than the current day's price. If there is no such price, output -1 for that day.
Input Format:
- The first line contains an integer n (1 <= n <= 10^5), the number of days.
- The second line contains n space-separated integers, representing stock prices.
Output Format:
- Output a single line containing n space-separated integers, representing the most recent higher stock price from prior days.
Example:
Input:
5
100 80 90 70 110
Output:
-1 100 100 90 -1
Key concepts
monotonic_stackstock_pricesanomaly_detection
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