Reported September 2026
Amazonmonotonic stack

Next Smaller Ticket Price

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon reported this one in September 2026, and the input size is the whole story. With up to 10^5 tickets, the obvious nested loop checks billions of pairs and dies. The problem is "Next Smaller Ticket Price": for each price, return the next strictly smaller value to its right, or -1. It's a monotonic stack problem wearing a ticket-pricing costume. If you've got the OA in a day or two, learn the one-pass stack pattern below. And if your mind goes blank mid-assessment, StealthCoder runs invisibly as a safety net and gives you the solution in real time.

The problem

You are given an integer array prices, where prices[i] is the price of ticket i.
For each ticket, find the next strictly smaller price to its right. If no later ticket is cheaper, the answer for that ticket is -1.
Return an array of the same length as prices containing those answers in index order.

Function
nextSmallerPrices(prices: int[]) → int[]

Examples
Example 1
prices = [8,4,6,2,3]
return = [4,2,2,-1,-1]
Ticket 8 is followed by cheaper 4. Ticket 4 is followed by cheaper 2. Ticket 6 is followed by cheaper 2. Tickets 2 and 3 have no later cheaper price.
Example 2
prices = [5,4,3,2,1]
return = [4,3,2,1,-1]
Each ticket is immediately followed by a cheaper ticket except the last.
Example 3
prices = [1,2,3]
return = [-1,-1,-1]
Every later ticket is more expensive, so every answer is -1.

Constraints
1 <= prices.length <= 10^5.
1 <= prices[i] <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Brute force is O(n^2). With n up to 10^5 that's roughly 10^10 comparisons in the worst case, so it times out on a descending or flat-ish array. The trick is a monotonic stack of indices. Scan left to right. While the stack isn't empty and the current price is strictly less than the price at the stack's top index, pop that index and set its answer to the current price. Then push the current index. Anything left on the stack at the end gets -1, so initialize the result array with -1. Each index is pushed and popped once, so it's O(n). The common pitfall is strictness. Equal prices must not pop, so use < and not <=. Another slip is storing values instead of indices, which loses where to write the answer. If you freeze live, StealthCoder is the hedge that reads the problem and hands you this.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Next Smaller Ticket Price cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Next Smaller Ticket Price FAQ

What's the trick for Next Smaller Ticket Price?+

Use a monotonic stack of indices. Walk the array once. While the current price is strictly lower than the price at the top of the stack, pop and record the current price as that index's answer. Push the current index. Leftovers stay -1. It runs in O(n).

Why does brute force fail here?+

The constraint is up to 10^5 tickets. A nested loop checking every later ticket is O(n^2), which is around 10^10 operations on bad inputs like a long non-decreasing array. That's far too slow for the assessment, so you need the linear stack approach.

How do I handle equal prices?+

The problem says strictly smaller, so equal prices don't count. Pop only when the current price is less than the price at the stack top, using < and not <=. Test with [3,3,2] in your head. The expected result is [2,2,-1].

Is this pattern still asked by Amazon?+

It was reported in September 2026 for Amazon, so yes, it's showing up. Next-greater and next-smaller element problems are a staple because they test whether you spot the monotonic stack instead of defaulting to nested loops.

How do I prepare for this in 48 hours?+

Write the next smaller element solution from scratch three times until the stack loop is automatic. Then do the variants: next greater, previous smaller, and daily temperatures. Check edge cases like a single element, all equal values, and strictly descending or ascending arrays.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it