Field note / fundamentals

publishedupdated 2026-05-04#algorithms#stack#queue#monotonic-stack#bfs

Coding Practice: Stack and Queue

Ten medium-level stack and queue questions covering bracket validation, undo history, monotonic stacks, BFS queues, and scheduling.

TL;DR

  • Stacks model nested state and deferred resolution well.
  • Queues model breadth-first work, scheduling, and rate-limited processing well.
  • In frontend interviews, these patterns often show up in parsers, browser history, and asynchronous task reasoning.

Context

These data structures are practical. Stacks help with nested markup, undo flows, and nearest-greater problems. Queues help with level-order traversal, job processing, and buffering work in order.

The Approach

Practice these 10 medium-level questions:

  1. Valid Parentheses — stack baseline.
  2. Min Stack — maintain constant-time min along with push/pop.
  3. Evaluate Reverse Polish Notation — operator stack execution.
  4. Daily Temperatures — monotonic stack for next-greater queries.
  5. Asteroid Collision — resolve directional conflicts with a stack.
  6. Browser History — back/forward navigation with two stacks.
  7. Queue Using Two Stacks — understand amortized behavior.
  8. Task Scheduler Cooldown — queue plus remaining work accounting.
  9. Sliding Window Maximum — deque for monotonic candidates.
  10. Number of Recent Calls — queue-based rolling time window.

Try it in the browser

Browser Practice

Stack practice: valid brackets

Implement solve(value) and return true when all brackets are balanced and properly nested.

Sample Tests
3 checks
Function name: solve
Best for JavaScript / TypeScript / JSON practice snippets.Monospace editorRuns in browser sandbox

Trade-offs

  • Stack and queue solutions are elegant when the problem shape is right, but forced use of them can obscure simpler logic.
  • Monotonic structures are high leverage, though they are easy to miss if I do not recognize the “next larger/smaller” signal.

References