KatInterview

practice a little every day — you've got this ♡

Stacks & Queues Interview Problems

Practice 5969 original coding, SQL, system design, machine learning and behavioral problems across 15 topics. Coding and SQL problems run against hidden test cases right in your browser; every problem has hints and a worked solution, free.

5969
Problems
2211
Auto-graded
15
Topics
272
Added today

Showing 31–60 of 93 results

  • Stacks & QueuesMediumAuto-graded
    Expand Nested Repeat Notation in a Compressed String

    Parse a string with nested count-and-bracket repeat markers and expand it fully, testing recursive or stack-based parsing and careful handling of multi-digit counts.

    Stacks & Queuesstringsstackrecursionparsing
  • Stacks & QueuesMediumAuto-graded
    Longest Well-Formed Bracket Run

    Find the length of the longest contiguous well-formed stretch in a string of only round brackets, testing stack-based index tracking and handling of unmatched characters.

    Stacks & Queuesstackstringparenthesestwo-pass
  • Stacks & QueuesMediumAuto-graded
    Unscramble a Cipher-Encoded Nested Outline

    Parse a parenthesized pre-order tree string with a stack and undo a letter-substitution cipher, where each node's text is the run just before its closing parenthesis.

    Stacks & Queuesstackstring-parsingtree-deserializationsubstitution-cipher
  • Stacks & QueuesEasyAuto-graded
    Stack Simulator with Constant-Time Minimum Queries

    Simulate a sequence of stack commands and answer minimum queries in constant time by tracking the running minimum alongside each element.

    Stacks & Queuesstackdesignsimulationauxiliary-stack
  • Stacks & QueuesEasyAuto-graded
    Calculate Rolling Means from a Data Stream

    Evaluate tracking a sliding window over incoming numbers to incrementally update and output moving averages.

    Stacks & Queuessliding-windowqueuedequearray
  • Stacks & QueuesMediumAuto-graded
    Rounds of Pruning in a Garden Row

    Count how many rounds of simultaneous removals occur in a row of numbers where each element larger than its left neighbor is removed, using a monotonic stack to beat quadratic simulation.

    Stacks & Queuesmonotonic-stacksimulationarraysamortized-analysis
  • Stacks & QueuesMediumAuto-graded
    Widest Span Between Two Dominating Ends

    Find the longest subarray whose two end values are each strictly larger than everything between them, using a monotonic stack to avoid checking all pairs.

    Stacks & Queuesmonotonic-stackarraysnearest-greateramortized-analysis
  • Stacks & QueuesMediumAuto-graded
    Rebuild Call Start/Stop Events from Stack Snapshots

    Diff consecutive call-stack snapshots by longest common prefix to produce correctly ordered start and end events, including recursion, empty stacks and final closing.

    Stacks & Queuesstacksimulationlongest-common-prefixarrays
  • Stacks & QueuesMediumAuto-graded
    Eager Deletion of Repeated Character Blocks

    Scan a string and delete each block of k equal adjacent characters as soon as it forms, handling cascading merges with a run-length stack.

    Stacks & Queuesstackstringrun-lengthsimulation
  • Stacks & QueuesMediumAuto-graded
    Evaluate Nested Prefix Expressions with Scoped Bindings

    Parse and evaluate a parenthesized prefix language with sum, prod and set, handling lexical scoping, strict validation and 32-bit overflow rules.

    Stacks & Queuesparsingrecursionscopingstack
  • Stacks & QueuesMediumAuto-graded
    Finish Times for a Single Worker with a Limited Waiting Line

    Simulate a one-worker FIFO queue with a capped waiting line and report each job's finish time or -1 if it was rejected, using a deque of finish times.

    Stacks & Queuesqueuedequesimulationamortized-analysis
  • Stacks & QueuesMediumAuto-graded
    Self-Time Accounting for Nested Call Traces

    Use a stack to turn start/end trace records of nested calls on one CPU into each function's self-time, with inclusive end timestamps.

    Stacks & Queuesstackparsingsimulationstrings
  • Stacks & QueuesMediumAuto-graded
    Checkout Totals After Next Cheaper Coupon Item

    Find, for each element, the nearest later value that is less than or equal to it and subtract it, which tests monotonic stack reasoning on arrays.

    Stacks & Queuesmonotonic-stackarraysnext-smaller-element
  • Stacks & QueuesMediumAuto-graded
    Largest Block Under a Skyline of Columns

    Compute the largest rectangle that fits under a row of unit-width columns, testing monotonic stack usage and boundary reasoning over contiguous ranges.

    Stacks & Queuesmonotonic-stackarrayhistogramcontiguous-range
  • Stacks & QueuesMediumAuto-graded
    Rebuild an Outline Tree from Depth-Tagged Lines

    Turn a flat sequence of (depth, label) entries into a nested tree by attaching each entry to its nearest earlier entry with a smaller depth, using a monotonic stack.

    Stacks & Queuesstacktree-constructionparsingmonotonic-stack
  • Stacks & QueuesMediumAuto-graded
    Unnest Deeply Nested Lists Without Recursion

    Flatten an arbitrarily nested Python list into a single list in left-to-right order, treating only lists as containers and handling very deep nesting safely.

    Stacks & Queuesstackiterationnested-listsdepth-first-search
  • Stacks & QueuesMediumAuto-graded
    Validate Balanced Round, Square and Curly Brackets

    Decide whether a string of three bracket kinds is balanced, testing last-in-first-out matching with a stack and handling crossings and leftover or stray brackets.

    Stacks & Queuesstackstringsparsingbracket-matching
  • Stacks & QueuesEasyAuto-graded
    Nested Delimiter Checker for Config Expressions

    Checks whether a string of mixed parentheses, braces, and square brackets is properly nested, testing stack-based matching and early rejection in linear time.

    Stacks & Queuesstackparsingstringmatching
  • Stacks & QueuesHardAuto-graded
    Reconstruct Function Lifetimes from Periodic Stack Snapshots

    Tests ability to diff consecutive call-stack snapshots using longest-common-prefix analysis and stack unwinding to produce ordered START/END lifecycle events.

    Stacks & Queuesstacksimulationtwo-pointers
  • Stacks & QueuesHardAuto-graded
    Peak Values in Fixed-Length Subarrays

    Tests understanding of monotonic deques to efficiently track the largest element across consecutive fixed-size subarrays in linear time.

    Stacks & Queuesdequesliding-windowmonotonic-queue
  • Stacks & QueuesEasyAuto-graded
    Balanced Delimiter Validation with a Stack

    Decide whether a bracket-only string is properly nested and matched, using a LIFO stack of pending openers.

    Stacks & Queuesstackstringsparsing
  • Stacks & QueuesHardAuto-graded
    Simulate a FIFO Queue with Two Stacks

    Tests whether you can emulate first-in-first-out ordering using only two LIFO stacks and explain the amortized cost of each operation.

    Stacks & Queuesstacksqueueamortized-analysis
  • Stacks & QueuesMediumAuto-graded
    Single-Threaded CPU: Exclusive Runtimes and Stack Snapshot

    Tests stack simulation and interval reasoning by computing per-function exclusive execution time and reconstructing the active call stack at a query timestamp from a sorted event log.

    Stacks & Queuesstacksimulationinterval-reasoning
  • Stacks & QueuesMediumAuto-graded
    Bracket Nesting Check and Rotating Cipher

    Tests stack-based bracket validation and modular arithmetic to rotate lowercase letters circularly across the alphabet.

    Stacks & Queuesstacksstringsmodular-arithmetic
  • Stacks & QueuesMediumAuto-graded
    Calculate Arithmetic Expression with Negation and Grouping

    Tests building an operator-precedence parser using stacks to handle binary operations, unary negation, parentheses, and zero-truncating division.

    Stacks & Queuesstacksparsingoperator-precedencestring-processing
  • Stacks & QueuesMediumAuto-graded
    Cascade Removal of Equal Neighbor Groups

    Tests stack-based simulation of iterative removals that trigger chain reactions when fragments recombine.

    Stacks & Queuesstackstringsimulation
  • Stacks & QueuesMediumAuto-graded
    Skyline Visible Buildings Count

    Tests ability to use a monotonic stack to count, for each building, how many previous buildings are visible looking back from it along a city skyline.

    Stacks & Queuesmonotonic stackarrayssimulation
  • Stacks & QueuesMediumAuto-graded
    Bracket Matching, Interval Union, and Expression Parsing

    Tests stack-based bracket validation, interval merging with endpoint semantics, and arithmetic evaluation with unary operators.

    Stacks & Queuesstacksintervalsparsingexpression-evaluation
  • Stacks & QueuesMediumAuto-graded
    Trim a Bracket String to Its Longest Balanced Form

    Tests stack-based bracket matching: find and remove the fewest characters from a parentheses-only string to leave a fully balanced result.

    Stacks & Queuesstacksstringsgreedy
  • Stacks & QueuesMediumAuto-graded
    Identify Invalid Parentheses for Removal

    Tests stack-based matching to find the minimum set of parenthesis indices that must be removed to balance a string.

    Stacks & Queuesstackstring-processinggreedy