← 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?
- A.O(n²)
- B.O(n)
- C.O(n log n)
- 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 →