Frage im Vorstellungsgespräch bei Amazon

Simple stack question, with an optimization to reduce run time.