Dsa
Monotonic Stack
Medium
Stock Price Sequence
Given an array of integers representing the prices of a stock on each day, write a program that returns an array where each element indicates the number of consecutive days ending on that day where the stock price was lower than or equal to that day’s price.
Input Format:
- A single line containing space-separated integers representing the stock prices for n days.
Output Format:
- A single line containing space-separated integers representing the count of lower or equal prices for each day.
Example:
Input:
3 6 5 4 3 5 7
Output:
1 2 1 1 1 2 3
Key concepts
monotonic_stackstock_pricingmax_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