I have thought about it for a while, and I'm not really sure what is the best way to:

1.Implement a stack using 2 queues.

2.Implement a queue using 2 stacks.

I have only though about something trivial that takes O(n) time for dequeue and enqueue, and O(n) time for push and pop.

Can I do better than that? Are there more efficient ways to do 1 and 2?



Browse other questions tagged or ask your own question.