← 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)?
- A.It sorts after every push
- B.Each entry also stores the minimum at that level of the stack
- C.It scans the stack on every getMin
- 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 →