What is the difference between a stack and a queue?
What is the difference between a stack and a queue?
Approach: Compare LIFO and FIFO access patterns.
A stack follows Last-In-First-Out (LIFO); the last element added is the first one removed. A queue follows First-In-First-Out (FIFO); the first element added is the first one removed.
Follow-up: How can you implement a queue using two stacks?
Key concepts: lifo, fifo, push/pop.