Begin Algo
Data structures · 4 lessons

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 up
Bracket matching and undo in an editor

Push on an opening bracket, pop and compare on a closing one. Ctrl+Z is the same thing: push every action, pop to undo.

→ Lesson: Stack
Print spoolers and message queues

The job sent first prints first; the message received first is handled first. Kafka and RabbitMQ are queues at their core.

→ Lesson: Queue & Deque
"When is the next day the price is higher?"

Asking 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
Window maximum on a dashboard

"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

Lessons

4 lessons