← 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"?
- A.Walk from right to left
- B.Pop while the top is GREATER than x
- C.Use a queue instead of a stack
- 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 →