Stacks & Queues mind map
LIFO/FIFO structures and monotonic patterns.
Core idea: Ask who must wait: newest unfinished work uses a stack; oldest ready work uses a queue.
Mnemonic: Push → resolve → process · Cost: O(n) amortized · ordered waiting
Frame: Syntax & evaluation
Signal: A token must close or resume the newest unfinished context.
Move: Push opens, operands, or frames; a closing token resolves the top context.
Examples: Valid Parentheses, Calculator, Decode String
Resolve: Monotonic stack
Signal: Each item asks for its next greater, smaller, or blocking boundary.
Move: Pop weaker items; the current index becomes the answer or boundary for each popped index.
Examples: Daily Temperatures, Largest Rectangle, Next Greater Element
Expire: Monotonic deque
Signal: A moving window repeatedly needs its maximum or minimum.
Move: Remove stale indices at the front and weaker candidates at the back.
Examples: Sliding Window Maximum, Shortest Subarray, Max Queue
Process: FIFO layers
Signal: Arrival order or unweighted distance must be preserved.
Move: Enqueue newly ready states once; process the current breadth before the next.
Examples: Tree Level Order, Rotting Oranges, Queue Using Stacks