Final Prices With a Special Discount in a Shop
A easy-tier problem at 83% community acceptance, tagged with Array, Stack, Monotonic Stack. Reported in interviews at Dream11 and 0 others.
Final Prices With a Special Discount in a Shop is an easy problem that looks deceptively simple until you misread the constraint. You have an array of prices and need to apply a discount rule: for each price, find the first item to its right that costs less or equal, and subtract that value. If no such item exists, the price stays unchanged. Dream11 has asked this one. The trick isn't the algorithm, it's recognizing the monotonic stack pattern saves you from an O(n^2) brute force that looks correct on small test cases but tanks on large ones.
Companies that ask "Final Prices With a Special Discount in a Shop"
Final Prices With a Special Discount in a Shop is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderMost candidates will write nested loops: for each price, scan right until you find a smaller value, apply the discount, done. It passes some cases, then times out. The pattern here is monotonic stack. You iterate right to left, maintain a stack of prices in increasing order, and for each price pop everything larger than it off the stack. The top of the stack is your discount target. This is a classic 'next smaller element' problem in disguise. StealthCoder catches this pattern instantly during your assessment, if you blank on the stack approach and start coding nested loops, you'll see a working monotonic stack solution invisible to the proctor, letting you paste the real logic before the timer burns.
Pattern tags
You know the problem.
Make sure you actually pass it.
Final Prices With a Special Discount in a Shop recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Final Prices With a Special Discount in a Shop interview FAQ
Is this actually easy or a hard problem labeled easy?+
It's genuinely easy in terms of code length and edge cases. The acceptance rate is 83%, which confirms most people solve it. The catch is performance. Brute force works on small inputs, so many candidates submit and move on. But the stack approach is what interviewers actually want to see.
Why is this a monotonic stack problem?+
You need the next smaller-or-equal element to the right of each price. That's the textbook definition of a monotonic stack use case. A stack maintains candidates in increasing order as you scan backwards, and each price pops all larger candidates, leaving the answer on top.
Can I use a hash map or binary search instead?+
Not efficiently for the general case. A hash map doesn't order the search space. Binary search requires sorted data on the right, which you don't have. Monotonic stack is O(n) with O(n) space and handles this problem's constraint perfectly.
What's the common mistake that wastes time?+
Writing nested loops and testing on small arrays, seeing it pass, then submitting. Time limit exceeded kills you after. Always ask yourself: does this loop inside a loop fit the constraints. If not, think stack or two-pointer patterns.
Does Dream11 ask this during final rounds or early screening?+
It's reported as asked by Dream11, but the difficulty and acceptance rate suggest it's a screener problem rather than a final-round question. Use it as a warm-up to practice stack patterns before tackling harder variants.
Want the actual problem statement? View "Final Prices With a Special Discount in a Shop" on LeetCode →