Amazon Interview Question

Designing a stack like data structure(push, pop) and a min() function which operates in constant time

Interview Answer

Anonymous

Oct 22, 2014

One can use a stack, this gives you push()/ pop() operations. Modify it, instead of storing one value - store two. The other value is minimum under given element. Thus min() will just read the other value in constant time.