Skip to content

Monotonic Stack problems,
and the tell.

You need the next or previous element that is greater or smaller, for every position. 38 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. You need the next or previous element that is greater or smaller, for every position.

The mechanism. Keep a stack that only ever rises or only ever falls. Each new element pops the ones it answers, so every element is pushed and popped once and the whole scan is linear.

What goes wrong. Picking the wrong direction. Next greater needs a decreasing stack, and the mirror image for the other three variants.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Number of Visible People in a QueueHardasked at 6 companies
  2. Smallest K-Length Subsequence With Occurrences of a LetterHardasked at 1 companies
  3. Final Prices With a Special Discount in a ShopEasyasked at 0 companies
  4. Number of Valid SubarraysHardasked at 1 companies
  5. Online Stock SpanMediumasked at 1 companies
  6. Shortest Unsorted Continuous SubarrayMediumasked at 1 companies
  7. Maximum Array Hopping Score IMediumasked at 1 companies
  8. Maximum Array Hopping Score IIMediumasked at 1 companies
  9. Subarray With Elements Greater Than Varying ThresholdHardasked at 1 companies
  10. Find Building Where Alice and Bob Can MeetHardasked at 1 companies

Read it, watch it, then solve it.

The order that makes a pattern stick.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About monotonic stack problems.

Free to start, no card.

Start practising
How do I know a problem is a monotonic stack problem?

You need the next or previous element that is greater or smaller, for every position.

How many monotonic stack problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 38, split roughly 2 easy, 25 medium and 11 hard in the sample we show, so work up rather than across.

What goes wrong most often in monotonic stack problems?

Picking the wrong direction. Next greater needs a decreasing stack, and the mirror image for the other three variants.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.