Stack & QueueLast in first out, first in first out
A stack remembers what happened most recently, a queue what happened earliest. Both are simple enough to build on an array, yet they are exactly what separates DFS from BFS — and monotonic stacks and queues are how you turn O(n²) into O(n).
Why learn Stack & Queue
Where it shows upPush on an opening bracket, pop and compare on a closing one. Ctrl+Z is the same thing: push every action, pop to undo.
→ Lesson: StackThe job sent first prints first; the message received first is handled first. Kafka and RabbitMQ are queues at their core.
→ Lesson: Queue & DequeAsking that for every day is O(n²) by brute force. A monotonic stack does one pass, with each element pushed and popped exactly once.
→ Lesson: Monotonic Stack"What was the worst latency in the last 60 seconds?", asked every second. A monotonic queue keeps that answer O(1) as the window slides.
→ Lesson: Monotonic Queue