🎙 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 5 of 8

How does a Min Stack return the minimum in O(1)?

How does a Min Stack return the minimum in O(1)?

  1. A.It sorts after every push
  2. B.Each entry also stores the minimum at that level of the stack
  3. C.It scans the stack on every getMin
  4. D.It uses a queue
Answer & explanation

Correct answer: Each entry also stores the minimum at that level of the stack

Storing (value, min-so-far) pairs means the top always knows the current minimum.

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 →