Google Interview Question

How would you implement a stack to achieve constant time for "push", "pop" and "find mininum" operations?

Interview Answers

Anonymous

May 15, 2010

The catch is to use another stack to remember the minimum. The other operations already take constant time.

1

Anonymous

Aug 12, 2014

With an array you can implement in Push/Pop in constant time. The expansion/contraction of the array can be implemented such that the amortized cost is constant.