🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Monotonic Stack: all 13 questions

Quiz: Monotonic Stack · Question 5 of 13

Which change turns "next greater" into "next smaller"?

Which change turns "next greater" into "next smaller"?

  1. A.Walk from right to left
  2. B.Pop while the top is GREATER than x
  3. C.Use a queue instead of a stack
  4. D.Sort the array first
Answer & explanation

Correct answer: Pop while the top is GREATER than x

Reversing the comparison keeps an increasing stack, and popped elements get their next smaller.

Can you get the rest right without peeking?

Take the timed Quiz: Monotonic Stack quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →