Microsoft Interview Question

Getting the min from a stack in O(1) time

Interview Answers

Anonymous

Mar 24, 2019

Using two stacks

Anonymous

Mar 31, 2019

Use two stacks and keep track of the min so far in it at each level. Make sure the push and pop syncs the min stack and make it same length.

Anonymous

Apr 25, 2020

the min object can be anywhere inside it, you have to go through all of the stack and search for it (doesn't matter which way you go through it...) which means O(n), or am I missing something?