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

Stack & Queue Quiz · Question 7 of 8

What is the time complexity of the monotonic stack solution for next greater element?

What is the time complexity of the monotonic stack solution for next greater element?

  1. A.O(n²)
  2. B.O(n)
  3. C.O(n log n)
  4. D.O(1)
Answer & explanation

Correct answer: O(n)

Each index is pushed once and popped at most once.

Can you get the rest right without peeking?

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

Start the quiz →