Dsa
Monotonic Stack
Medium
Stock Price Peaks
Consider the stock prices of a company over a given number of days. A peak stock price is defined as a price that is greater than all the prices within the last 'k' days. Write a function that takes a list of stock prices and an integer 'k', and returns a list of boolean values indicating whether each day's stock price is a peak price based on the last 'k' days.
Input format:
- The first line contains a space-separated list of integers representing the daily stock prices.
- The second line contains an integer 'k'.
Output format:
- A single line containing space-separated boolean values (True or False) indicating peak prices.
Example:
Input:
100 80 120 90 110 130 95
3
Output:
True False True False True True False
Key concepts
monotonic_stackstock pricesarrays
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