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 1–30 of 93 results

  • Stacks & QueuesEasyAuto-graded
    Typed Value Stack Interpreter with Mixed Addition

    Simulate a stack machine whose values are tagged ints or strings, where ADD sums two ints or concatenates otherwise, and return the printed lines.

    Stacks & Queuesstacksimulationstringstagged-union
  • Stacks & QueuesMediumAuto-graded
    Fixed-Width Window Folds with Add, Multiply, or AND

    Compute the fold of every length-k window of an array under a named associative operation, ideally in linear time without relying on inverse operations.

    Stacks & Queuessliding-windowtwo-stacksassociative-operationqueue
  • Stacks & QueuesMediumAuto-graded
    Collapse Adjacent Edits Before Applying Them to a Text Buffer

    Simulate a queue of insert and format edits, merging adjacent inserts and dropping repeated adjacent formats, then return the final text and ordered list of applied styles.

    Stacks & Queuesstacksimulationcommand-patternstrings
  • Stacks & QueuesMediumAuto-graded
    Normalize a Filesystem Location String

    Reduce an absolute Unix-style path to its canonical form by resolving repeated slashes, current-directory and parent-directory segments, using a stack.

    Stacks & Queuesstackstring-parsingsimulationpaths
  • Stacks & QueuesEasyAuto-graded
    Leftover Brackets After Pairing Up a Parenthesis String

    Count the parentheses left over after forming the maximum number of valid "(" before ")" pairs, testing a greedy counter scan or stack over a string.

    Stacks & Queuesstackgreedystringsparentheses
  • Stacks & QueuesMediumAuto-graded
    Infer Execution Events from Call Stack Snapshots

    Reconstruct chronological function START and END lifecycle events by evaluating structural differences across consecutive call stack snapshots.

    Stacks & Queuesstacks-queuesarraysstrings
  • Stacks & QueuesMediumAuto-graded
    Four-Function Calculator Without Parentheses

    Evaluate a string of non-negative integers with +, -, *, / and spaces, honoring precedence and truncating division toward zero, without using eval.

    Stacks & Queuesstring-parsingstackoperator-precedencesimulation
  • Stacks & QueuesMediumAuto-graded
    Expand a Compressed Bracket Pattern String

    Tests stack-based parsing of nested repeat-count patterns, including multi-digit counts, nesting, and trailing letters, to rebuild the fully expanded string.

    Stacks & Queuesstackstringparsingnested-structures
  • Stacks & QueuesMediumAuto-graded
    Expand a Compact Pattern with Nested Multipliers

    Expand a string in which a positive integer followed by a bracketed block means that block repeats, with nesting; tests stack or recursive parsing and multi-digit number handling.

    Stacks & Queuesstackstring-parsingnested-structuresrecursion
  • Stacks & QueuesMediumAuto-graded
    Unwrap Deeply Nested Lists Into One Sequence

    Collect every integer from a structure of arbitrarily deep nested lists in left-to-right order, without recursion, so extremely deep inputs do not overflow the call stack.

    Stacks & Queuesstackdfsiteratorsnested-lists
  • Stacks & QueuesEasyAuto-graded
    Balanced Delimiters Checker

    Decide whether a string made only of round, square and curly brackets is correctly paired and nested, which tests stack-based matching and edge-case handling.

    Stacks & Queuesstackstringsparsing
  • Stacks & QueuesEasyAuto-graded
    Check Block Nesting in a Flat Marker Sequence

    Scan a list of tokens and decide whether every OPEN-style marker is matched by a later close marker, using a running counter and early rejection.

    Stacks & Queuescounterbalanced-bracketssingle-passstrings
  • Stacks & QueuesMediumAuto-graded
    Wait Time Until a Strictly Larger Sensor Value

    Find, for each position in a sequence, the distance to the next strictly larger element, using a monotonic stack to achieve linear time.

    Stacks & Queuesmonotonic-stackarraysnext-greater-element
  • Stacks & QueuesMediumAuto-graded
    Smallest Subsequence Containing Each Letter Once

    Build the lexicographically smallest subsequence that uses every distinct letter of a string exactly once, using a greedy monotonic stack with remaining-count tracking.

    Stacks & Queuesmonotonic-stackgreedystringssubsequence
  • Stacks & QueuesMediumAuto-graded
    Evaluate a Spaced Arithmetic String Without Parentheses

    Evaluate an integer expression with +, -, *, / using standard precedence and truncating division, in a single pass over a string with arbitrary spacing.

    Stacks & Queuesparsingstringstackoperator-precedence
  • Stacks & QueuesMediumAuto-graded
    Parenthesized Integer Calculator with Unary Negation

    Evaluate an integer expression with +, -, *, /, parentheses and unary minus in one iterative pass, using precedence rules and division that truncates toward zero.

    Stacks & Queuesstackparsingexpression-evaluationshunting-yard
  • Stacks & QueuesMediumAuto-graded
    Expand Nested Repeat Notation into a Full String

    Expand a string containing nested count[text] repeat groups into its full form, using a stack or recursion to parse multi-digit counts and nesting correctly.

    Stacks & Queuesstackstring-parsingnested-structuresrecursion
  • Stacks & QueuesMediumAuto-graded
    Deserialize Nested List Structure

    Parse a string encoding nested lists and non-negative integers into a Python list structure.

    Stacks & Queuesstacksstringsparsingrecursion
  • Stacks & QueuesMediumAuto-graded
    Strip Unmatched Brackets From a Text Line

    Delete exactly the brackets that cannot be paired so the remaining text is well-formed, using a single linear scan with a stack or counters.

    Stacks & Queuesstackstringparenthesesgreedy
  • Stacks & QueuesEasyAuto-graded
    Right-Side Larger Neighbor Lookup for Selected Values

    Tests whether you can precompute the nearest strictly larger value to the right for every element using a monotonic stack, then answer lookups for a chosen list of values.

    Stacks & Queuesmonotonic-stackhash-maparrays
  • Stacks & QueuesMediumAuto-graded
    Expand Nested Repeat Patterns in an Encoded String

    Tests stack-based parsing of nested, multi-digit repeat patterns of the form count[text] to rebuild the fully expanded string.

    Stacks & Queuesstackstring-parsingnested-structuredecoding
  • Stacks & QueuesMediumAuto-graded
    Longest Stretch With Bounded Spread

    Find the longest contiguous stretch of an integer list whose largest and smallest values differ by at most a tolerance, using a sliding window with monotonic deques.

    Stacks & Queuessliding-windowmonotonic-dequearraystwo-pointers
  • Stacks & QueuesMediumAuto-graded
    Resolve Field Paths in a Nested Message Schema

    Parse brace-delimited nested message definitions line by line, then check which dotted query paths name an actual field, tracking scope with a stack.

    Stacks & Queuesparsingstackhash-setstrings
  • Stacks & QueuesEasyAuto-graded
    Check Whether Bracket Pairs Are Correctly Nested

    Decide whether a string of round, square and curly brackets is well formed, which tests the use of a stack for last-in-first-out matching.

    Stacks & Queuesstackstringsparsing
  • 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