Understand that a stack removes from the same end it adds to (Last In, First Out), while a queue removes from the opposite end it adds to (First In, First Out) — and that both operations are O(1) regardless of how many items are stored.
Top is on the right — push/pop happen there
pushes: 0 · pops: 0
Front is on the left — enqueue at the right, dequeue from the left
last dequeued: —
Stack: push/pop at the top — Last In, First Out (LIFO)Queue: enqueue at the back, dequeue at the front — First In, First Out (FIFO)Both push/pop and enqueue/dequeue run in O(1) timePush 3 items onto the Stack, then pop 2 of them. Confirm the stack has exactly 1 item left.
Ready to check