Frage im Vorstellungsgespräch bei Amazon

Design a stack with min(stack) operation in constant time

Antworten zu Vorstellungsgespräch

Anonym

25. Mai 2012

The idea is to have a "current minimum" variable that you update on push. The trick is to save this current minimum with the node on push, so that once you pop you get the old "current minimum".

Anonym

25. Juli 2012

Using temporary variable is OKAY. But if pop operation is performed on curr minimum,it would be O(n) to update the new minimum