This was asked to me in an interview,
I was first asked to design a stack that does getMin()
in constant time. This is a fairly well known problem where you add an extra field to the stack element and maintain min
value. I was then asked to extend this functionality to provide popMin()
in constant time. I'm drawing a blank on how to do this. Any ideas?