Stacks & queuesExplained
Stack Using Queues
After each push, rotate the queue so the newest item is at the front.
Time
O(n) push or pop
Extra space
O(n)
Use it for
Implementing LIFO with FIFO parts.
After each push, rotate the queue so the newest item is at the front.
Time
O(n) push or pop
Extra space
O(n)
Use it for
Implementing LIFO with FIFO parts.