Dsa
Monotonic Stack
Easy
The Bargain Hunter
At a special thrift store, for every item you look at, you want to know the price of the very first item appearing to its right that is strictly cheaper. If no such cheaper item exists, the 'bargain price' for that item is 0. Output the bargain prices for all items in the sequence.
Input Format: A single line of space-separated integers representing item prices.
Output Format: A single line of space-separated integers representing the bargain prices.
Example:
Input: 10 7 8 5
Output: 7 5 5 0
Key concepts
monotonic_stacknext_smaller_element
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