KatInterview

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

Stacks & Queues Interview Problems

Practice 5967 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.

5967
Problems
2210
Auto-graded
15
Topics
272
Added today

Showing 31–60 of 112 results

  • Stacks & QueuesMediumModel answer
    Simulated Stock Trading Signals and Two-Char String Reduction

    Solve two streaming state problems: daily stock trading based on sign patterns in O(N) time and two-character substring elimination using an in-place stack.

    Stacks & Queuesstacks-queuesarraysstringsmath-bits
  • Stacks & QueuesMediumModel answer
    Build a Stack-Based Mini Language Interpreter in Python

    Write an interpreter that parses a line-based program of LOAD, STORE and integer arithmetic instructions, runs it on an operand stack, and returns the final variable memory.

    Stacks & Queuesinterpreterstackparsingerror-handling
  • Stacks & QueuesEasyAuto-graded
    Well-Formed Bracket Sequence Checker

    Decide whether a string of three kinds of brackets is correctly nested, using a stack to enforce that the most recently opened bracket is closed first.

    Stacks & Queuesstackstringmatchingparsing
  • Stacks & QueuesMediumAuto-graded
    Validate Deep Structure Equivalence

    Recursively or iteratively check if two arbitrarily nested data structures are identical in type, shape, and value.

    Stacks & Queuesrecursionstackdata-structureshashing
  • Stacks & QueuesEasyAuto-graded
    Cancel Neighboring Letter Pairs in a String

    Tests using a stack to repeatedly cancel adjacent equal characters in a string, including cascading cancellations, in linear time.

    Stacks & Queuesstackstringsimulation
  • Stacks & QueuesMediumAuto-graded
    Per-Function Self Time from a Call Trace

    Sweep a single-threaded call trace with a stack to total each function's self time under half-open intervals, with recursion, strict validation, and name-sorted output.

    Stacks & Queuesstacksimulationhash-mapvalidation
  • Stacks & QueuesEasyAuto-graded
    Collapse Repeated Letters: Pair Cancel or Full Run Wipe

    Simulate cascading deletions of equal neighbouring letters with a stack, either cancelling pairs or erasing whole leftmost runs, and return what is left.

    Stacks & Queuesstackstringsimulationrun-length
  • Stacks & QueuesHardAuto-graded
    Determine Pass Times for Single-Lane Security Gate

    Simulate the scheduling of access requests through a shared resource using state tracking and queues under conflict-resolution rules.

    Stacks & Queuesstacks-queuessimulationarrays
  • 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 & QueuesEasyModel answer
    Run a Tiny Postfix Command Interpreter with Error Codes

    Simulate a small stack machine over whitespace-separated tokens, handling arithmetic, DUP, POP and PRINT, and stop at the first error while keeping the output produced so far.

    Stacks & Queuesstacksimulationparsingerror-handling
  • Stacks & QueuesMediumModel answer
    Build a Multi-Room Async TCP Chat Server

    Implement a concurrent, room-based TCP chat server in Python using asyncio, featuring command processing, scoped broadcasts, backpressure handling, and strict resource cleanup.

    Stacks & Queuesconcurrencyasyncionetworkingpython
  • 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 & QueuesMediumModel answer
    Evaluate Arithmetic Expressions and Decode Nested Run-Length Strings

    Implement two production-ready string parsers: an arithmetic evaluator supporting basic operators and precedence, and a nested string expansion utility.

    Stacks & Queuesstackparsingstringsexpression-evaluation
  • 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 & QueuesMediumModel answer
    Predicting Output Order with the Browser Event Loop

    Work out the print order of a short script mixing timers, promises and microtasks, then explain how the browser event loop schedules each kind of task.

    Stacks & Queuesjavascriptevent-loopasyncmicrotasks
  • Stacks & QueuesMediumModel answer
    Evaluate Prize-Pool Formulas with Strictly Positive Whole Steps

    Parse and evaluate an infix arithmetic string, rejecting it with False if any intermediate result is zero, negative, or a non-integer quotient.

    Stacks & Queuesparsingrecursive-descentexpression-evaluationvalidation
  • 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