Google Interview Question: How would you implement a sta... | Glassdoor

Interview Question

Software Engineer Interview Mountain View, CA

How would you implement a stack to achieve constant time

  for "push", "pop" and "find mininum" operations?
data structures

Interview Answer

3 Answers


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

Interview Candidate on May 15, 2010

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.

Anonymous on Aug 12, 2014

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.