Days Until a Product's Price Rises Above Today's Price
Last updated: November 29, 2026
Quick Overview
Given a product's daily prices on Amazon, return a list where entry i is the number of days you must wait after day i for a strictly higher price, or 0 if no later day is higher.
Amazon
November 29, 20260
0
0 solved
Given a product's daily prices on Amazon, return a list where entry i is the number of days you must wait after day i for a strictly higher price, or 0 if no later day is higher.
The entry-level monotonic stack question in Amazon phone screens, framed around the price history that deal watchers and sellers track. The interviewer wants the decreasing stack of indices and an amortized O(n) argument.
What the Interviewer Expects
- Explains why the O(n^2) scan is too slow
- Keeps a stack of indices with decreasing prices
- Resolves waiting days when a higher price arrives
- Leaves 0 for unresolved indices
- Gives the amortized O(n) argument
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the next higher price itself rather than the wait.
- Find the previous higher price for each day instead.
- What if prices arrive as a stream and you must answer as soon as possible?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of prices (integers or floats), length up to 10^5. Output: list wait of the same length. Strictly higher only; equal prices do not count....
High-Level Design
Scan left to right holding a stack of day indices whose next higher price has not been found; their prices are non-increasing from bottom to top. When day i arrives, pop every index j with price[j] < ...