KatInterview

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

Coding Interview Problems

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

5966
Problems
2209
Auto-graded
15
Topics
271
Added today

Showing 31–60 of 2759 results

  • Arrays & HashingEasyAuto-graded
    Maximum Gain from Single Asset Trade

    Determine the maximum possible gain achieved by completing at most one purchase and sale transaction over a sequence of prices.

    Arrays & Hashingarraysgreedyprefix-minimum
  • Data Structure DesignMediumAuto-graded
    Smallest Free Label per Category: Batch Simulation

    Simulate a sequence of allocate and release operations on independent categories, always handing out the smallest free positive integer, using a counter plus a min-heap per category.

    Data Structure Designheaphash-mapsimulationdesign
  • Data Structure DesignMediumAuto-graded
    Design an In-Memory Key-Value Engine with Transactions

    Implement an in-memory key-value database supporting frequency counting and nested transaction rollbacks.

    Data Structure Designhash-tablestackdesigndata-structures
  • Data Structure DesignEasyAuto-graded
    Simulate a Time-To-Live (TTL) Key-Value Store

    Process a series of operations on an in-memory key-value store with fixed time-to-live expiration dynamics.

    Data Structure Designdesign-dshash-table
  • Heaps, Sorting & SearchMediumAuto-graded
    Podium Finish: Pick the Two Best Clubs in a League Table

    Rank teams with a multi-level tiebreak (points, goal difference, goals scored, index) and return the best two indices, testing composite keys and efficient selection.

    Heaps, Sorting & Searchsortingtuple-keystie-breakingselection
  • Data Structure DesignHardModel answer
    Build a Thread-Safe Dual-Resource Allocator

    Design a concurrency controller that manages exclusive access to two distinct targets while preventing deadlocks and invalid release calls.

    Data Structure Designconcurrencymultithreadinglockssynchronization
  • Data Structure DesignMediumModel answer
    Debugging a LinkedHashMap-Based Eviction Cache in Java

    Review a Java cache built on LinkedHashMap that evicts the wrong entries, find each defect, write minimal failing tests, and produce a corrected version.

    Data Structure Designlru-cachejavalinkedhashmapdebugging
  • Arrays & HashingMediumAuto-graded
    Leave-One-Out Products Without Using Division

    Build an array where each entry is the product of all other entries, without division, in linear time, using prefix and suffix running products.

    Arrays & Hashingprefix-productsuffix-productarrayin-place
  • 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
  • Trees & GraphsMediumAuto-graded
    Minimum Hops Between Two Tasks in a Dependency Graph

    Find the fewest directed edges from a start node to a goal node in an acyclic graph, returning 0 for identical nodes and -1 when unreachable; tests BFS on unit-weight graphs.

    Trees & Graphsgraphbfsshortest-pathdag
  • Data Structure DesignEasyAuto-graded
    Simulate Driver Availability and Task Allocation

    Simulate driver registration and dispatch operations using standard queue processing and state tracking.

    Data Structure Designdata-structuresqueueshash-tablesimulation
  • 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
  • Data Structure DesignMediumAuto-graded
    Compute Compressed Vector Inner Product

    Process dynamic creation of compressed vectors and compute inner products using sparse representations.

    Data Structure Designarraysdesign-dshash-table
  • Greedy & IntervalsEasyAuto-graded
    Select Best Single Task Type

    Determine the task type index that maximizes total revenue within a given time budget using floor division and custom tie-breaking rules.

    Greedy & Intervalsgreedyarraysmath
  • Math & Bit ManipulationEasyAuto-graded
    Circle Pair Relationship Labeler

    Label each pair of circles by their geometric relationship using exact integer squared-distance comparisons and a strict rule order, including degenerate radius-zero cases.

    Math & Bit Manipulationgeometryinteger-arithmeticcase-analysissimulation
  • Data Structure DesignMediumAuto-graded
    Design a Recency-Tracking Key-Value Store

    Simulate operations on a custom key-value map that efficiently queries the most recently updated active entry.

    Data Structure Designdesign-dslinked-listsarrays
  • Arrays & HashingMediumAuto-graded
    Per-Move Win Tracker for a Square Noughts-and-Crosses Grid

    Replay a sequence of marks on an n-by-n grid and report after each one whether the mover has completed a row, column or diagonal, using per-line counters.

    Arrays & Hashingsimulationcountingmatrixdiagonals
  • Trees & GraphsMediumAuto-graded
    Collect Allowed Values Depth by Depth from a Nested-List Tree

    Traverse a binary tree given as nested lists level by level and keep only values from an allowed set, preserving left-to-right order and empty levels.

    Trees & Graphsbinary-treelevel-orderbfsstack
  • Math & Bit ManipulationEasyAuto-graded
    Exact Staffing for a 2:1 Nail-to-Screw Quota

    Compute the headcount of two specialist worker types so a component quota splits exactly 2:1 with every worker at full capacity, or report that no such staffing exists.

    Math & Bit Manipulationmathratiosdivisibilitymodular-arithmetic
  • Math & Bit ManipulationEasyAuto-graded
    Dice Duel Probability with Optional Blind Reroll

    Calculate the exact win probability in a dice duel where one player uses an optimal single blind reroll strategy.

    Math & Bit Manipulationmathprobabilitygreedy
  • StringsEasyAuto-graded
    Pick the Tightest Wildcard Mask for a Bit String

    Scan a list of 0/1/? templates, keep those that fit a bit string, and return the one with the fewest wildcards, breaking ties by earliest position.

    Stringsstringspattern-matchinglinear-scantie-breaking
  • Greedy & IntervalsHardAuto-graded
    Union Overlapping Road Pieces That Share a Straight Line

    Group integer-point polylines by the exact line they lie on, then merge overlapping or touching extents on each line into one sorted point list.

    Greedy & Intervalsintervalsgeometrygcdhashing
  • Data Structure DesignMediumModel answer
    Audited Lazy File Streaming with Generators, Decorators and with

    Build a decorator that audits a chunked file-reading generator's lifecycle, with deterministic file cleanup on completion, early exit, errors and garbage collection.

    Data Structure Designpythongeneratorsdecoratorscontext-managers
  • Heaps, Sorting & SearchMediumModel answer
    Find Index of Local Minimum Using Binary Search

    Locate a local minimum in an array of integers in logarithmic time while handling flat regions and boundaries.

    Heaps, Sorting & Searcharraysbinary-searchalgorithms
  • StringsEasyAuto-graded
    Query-Driven Text Wrapper with Last-Line Balancing

    Parse a URL query string by hand, then greedily wrap the text to a width and fix a lone last-line word by borrowing from the previous line.

    Stringsstring-parsinggreedysimulationtext-wrapping
  • Heaps, Sorting & SearchMediumModel answer
    Implement Weighted Index Selector with Efficient Retrieval

    Design a data structure that accepts an array of positive item weights and samples indices proportional to their relative weight values.

    Heaps, Sorting & Searchbinary searchprefix sumrandom samplingdesign-ds
  • Arrays & HashingEasyAuto-graded
    Find Peak Positions in an Integer Sequence

    Scan an integer list and return the indices of elements strictly larger than every neighbor that exists, handling the ends, plateaus, and tiny inputs correctly.

    Arrays & Hashingarraystraversalboundary-conditions
  • Data Structure DesignMediumModel answer
    Making a Memoizing Python Function Safe for Many Threads

    Critique a Python function that caches expensive results in a dict, then make it thread-safe so each input is computed once, without blocking cache hits or unrelated inputs.

    Data Structure Designpythonconcurrencycachinglocking
  • Arrays & HashingMediumAuto-graded
    Quickest Kilometer Within a Run Recorded in 5-Second Splits

    Find the highest average speed over any 1000 m stretch of a run given per-5-second distances, using prefix sums, binary search and interpolation at boundaries.

    Arrays & Hashingprefix-sumsbinary-searchsliding-windowinterpolation
  • Trees & GraphsMediumAuto-graded
    Group Staff Names by Reporting Depth

    Turn flat employee-manager records into a list of name groups by depth from the top manager, using a level-by-level breadth-first traversal.

    Trees & Graphsbfstreehash-maplevel-order