Question: Implement Queue using stack. How many stacks you need? Note that you can only use following functions on a queue.

enQueue() deQueue() isEmpty() isFull()

And your stack should support following operations.
push() pop() isEmpty() isFull()


Solution: This can be done using 2 stacks say stack1 and stack2.
1) enQueue() can be implemented using push() on stack1.
2) isEmpty() and isFull() will work similar to stack1's isEmpty() and isFull() functions.
3) deQueue() will be done as following:
a) pop() all elements from stack1 and push() them in stack2( reversing their order from stack1- LIFO to FIFO).
b) Use pop() on stack2 to delete that element.
c) pop() all elements from stack2 and push() them in stack1.

So now deQueue() operation will cost you O(n) than O(1).