Question bank › Monotonic Stack
Dsa Monotonic Stack Medium

Stock Price High/Low Intervals

You are analyzing stock prices for a company and you have a list of daily prices. For each day, you want to find out how many days it took to see a lower price compared to today's price. If today's price is the lowest so far, return 0. Write a program that reads an integer n (the number of days) followed by n integers representing the stock prices. Print a single line with n integers representing the count of days until a lower price for each day. Input format: - The first line contains a single integer n (1 <= n <= 100000). - The second line contains n space-separated integers, where each integer is between 1 and 10^6 (inclusive). Output format: - A single line with n space-separated integers, the count of days until a lower price. Example: Input: 5 100 80 60 120 50 Output: 0 1 1 1 0

Key concepts

monotonic_stackstockprice

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.