Amazon interview question

Design a stack with any number of queue

Interview Answer

Anonymous

Nov 11, 2012

2 Queues Enqueu : Just push the element on stack1 Dequeue: Check if there are any elements on stack2, if there are the pop element from stack 2. If it is empty then pop n-1 element from stack1 to stack2 and pop the last element from stack1.