KatInterview

Topic

Stacks & Queues interview problems

Monotonic stacks, parsing and simulation. 112 original problems, each with hidden test cases you can run in the browser.

Problems112

22 easy74 medium16 hard

Showing 1–30 of 112 results

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

    Auto-gradedstacksimulationstringstagged-union
  • 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.

    Auto-gradedsliding-windowtwo-stacksassociative-operationqueue
  • For each person in a row, count how many people further right they can see when anyone standing between must be shorter than both of them. Needs an O(n) approach.

    Model answermonotonic-stackarraysamortized-analysisnext-greater-element
  • Explore the internal architecture, thread-safety mechanisms, and practical performance trade-offs of Java's ConcurrentHashMap and concurrent queue variants.

    Model answerjavaconcurrencydata-structuresmultithreading
  • 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.

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

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

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

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

    Auto-gradedstring-parsingstackoperator-precedencesimulation
  • Write a linear-time evaluator for integer expressions with variables, precedence, unary signs, parentheses, truncating division and 64-bit error handling.

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

    Auto-gradedstackstringparsingnested-structures
  • 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.

    Auto-gradedstackstring-parsingnested-structuresrecursion
  • 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.

    Auto-gradedstackdfsiteratorsnested-lists
  • 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.

    Auto-gradedstackstringsparsing
  • 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.

    Auto-gradedcounterbalanced-bracketssingle-passstrings
  • Find, for each position in a sequence, the distance to the next strictly larger element, using a monotonic stack to achieve linear time.

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

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

    Auto-gradedparsingstringstackoperator-precedence
  • Implement a lexer, recursive-descent parser and evaluator for a small integer language with variables, unary minus, precedence, truncating division and print.

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

    Auto-gradedstackparsingexpression-evaluationshunting-yard
  • Compute the integer result of a string holding non-negative numbers, four operators and spaces, honoring precedence and truncating division, without eval and with linear time.

    Model answerparsingstackstringoperator-precedence
  • 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.

    Auto-gradedstackstring-parsingnested-structuresrecursion
  • Parse a string encoding nested lists and non-negative integers into a Python list structure.

    Auto-gradedstacksstringsparsingrecursion
  • 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.

    Auto-gradedstackstringparenthesesgreedy
  • 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.

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

    Auto-gradedstackstring-parsingnested-structuredecoding
  • 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.

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

    Auto-gradedparsingstackhash-setstrings
  • 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.

    Auto-gradedstackstringsparsing
  • Analyze and fix a Python async script that finishes silently without invoking its async functions, and explore concurrent execution options with asyncio.

    Model answerpythonasyncioconcurrencydebugging

More topics