Frage im Vorstellungsgespräch bei Amazon

Implement a queue using stacks

Antwort im Vorstellungsgespräch

Anonym

21. Juni 2018

Use two stacks. Pushing operation is pushing to stack1. Popping returns value from stack 2. If stack2 is empty, pop values from stack1 and push on to stack 2 (reversing the order of how the elements are stored in stack1). Pop the top value from stack2.