KatInterview

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

Coding 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 650 results

  • Data Structure DesignMediumModel answer
    Deadlock-Free Atomic Funds Movement Between Shared Accounts

    Design a concurrent transfer operation over an in-memory account store that never loses updates, is all-or-nothing, preserves total money, and cannot deadlock.

    Data Structure Designconcurrencylockingdeadlockatomicity
  • Data Structure DesignMediumModel answer
    Python ABCs and the Three Kinds of Methods Explained

    Explain how abstract base classes work in Python and how instance, class and static methods differ in binding, inheritance behavior and typical use.

    Data Structure Designpythonoopabstract-classesclassmethod
  • Trees & GraphsHardModel answer
    Construct Non-Conflicting Queens Configurations

    Compute all possible configurations of n non-attacking queens on an n x n board using stateful depth-first search.

    Trees & Graphsbacktrackingrecursiondepth-first-search
  • Data Structure DesignMediumModel answer
    Handling Seekable Body Replays on 307 Redirects in Python requests

    Debug and implement stateful body rewind logic for seekable file-like streams when executing HTTP 307 redirects in an HTTP client library.

    Data Structure Designpythonhttpdebuggingstreams
  • Trees & GraphsHardModel answer
    Grid Partitioning and Navigating Safe Subregions

    Construct a valid contiguous layout for multiple crop zones on a grid and find the shortest path avoiding edge-touching zones.

    Trees & Graphstrees-graphsgridbfsconstructive-algorithms
  • Data Structure DesignMediumModel answer
    Design a Blackjack Game Engine

    Architect an object-oriented Blackjack engine handling multi-deck shoes, split hands, and soft/hard total calculations.

    Data Structure DesignData Structure DesignObject-Oriented DesignState Machine
  • Trees & GraphsMediumModel answer
    Graph Toolkit for Scene and Dependency Graphs: Sort, Traverse, Route

    Implement topological sort, BFS, DFS and Dijkstra on a dependency graph, then discuss CSR versus adjacency lists, CPU/GPU parallel traversal, and deterministic testing.

    Trees & Graphstopological-sortbfs-dfsdijkstracsr
  • Data Structure DesignMediumModel answer
    Build a Batch Grayscale Thumbnailer with Worker Pools

    Design and code a Pillow-based batch tool that grayscales and shrinks images, then scale it to many large files with multiprocessing, robust error handling, bounded memory and benchmarks.

    Data Structure Designpythonpillowmultiprocessingconcurrency
  • 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
  • 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
  • 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
  • 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
  • Stacks & QueuesMediumModel answer
    Line of Sight Counts for Each Person in a Row

    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.

    Stacks & Queuesmonotonic-stackarraysamortized-analysisnext-greater-element
  • Data Structure DesignMediumModel answer
    Versioned Follow Graph with Time-Travel Queries and Suggestions

    Build an in-memory directed follow graph with cheap snapshots, historical edge lookups, and a friends-of-friends suggestion ranking with id tie-breaks.

    Data Structure Designgraphsnapshotsbinary-searchheap
  • Data Structure DesignMediumModel answer
    Live Scoreboard Engine for One Tennis Game

    Process a sequence of point winners for a single tennis game and print the correct score after each point, including deuce, advantage and the win-by-two rule.

    Data Structure Designsimulationstate-designclass-designedge-cases
  • Data Structure DesignMediumModel answer
    Snapshot and Restore for an In-Memory String Map

    Build an in-memory string map in C++ that can dump its full state to a byte buffer and rebuild it, handling arbitrary bytes, corrupt input, and failed restores safely.

    Data Structure Designserializationbinary-formathash-mapinput-validation
  • Heaps, Sorting & SearchMediumModel answer
    Rolling Window Medians with Two Heaps and Lazy Removal

    Return the median of every length-k window of an integer array in O(n log k) time, handling duplicates, removals of departing elements, and the even-k convention.

    Heaps, Sorting & Searchsliding-windowheapmedianlazy-deletion
  • Data Structure DesignMediumModel answer
    Thread-Safe Ledger for Courier Payouts and Client Invoices

    Design an in-memory, thread-safe ledger that upserts delivery records and serves instant per-courier earnings and per-client invoice totals in integer cents.

    Data Structure Designconcurrencyhash-mapincremental-aggregationlow-level-design
  • Dynamic ProgrammingMediumModel answer
    Prune Minimum Nodes from Tree to Satisfy Height Budget

    Determine the minimal set of non-root node deletions required to trim a multi-child tree's height down to a target limit under node-promotion rules.

    Dynamic Programmingtrees-graphsdynamic-programmingtree-dp
  • Heaps, Sorting & SearchMediumModel answer
    Three Classics: Spaced Characters, Merged Streams, Cloned Lists

    Solve three linked tasks: rearrange a string so no neighbors match, merge k sorted linked lists, and deep-copy a linked list whose nodes carry an extra arbitrary pointer.

    Heaps, Sorting & Searchheapgreedylinked-liststring
  • Data Structure DesignMediumModel answer
    Design a Custom CSV Parsing and Filtering Engine

    Implement an in-memory CSV query processor with auto-type inference and polymorphic field filtering.

    Data Structure Designparsingdesign-dsstringsarrays
  • Trees & GraphsEasyModel answer
    Count Activations per Node in a Cascade Graph

    Given a DAG of task dependencies and one start node, compute how many times each node fires when every activation fans out once along every outgoing edge.

    Trees & Graphsdagtopological-sortpath-countinggraph-traversal
  • Heaps, Sorting & SearchMediumModel answer
    Assign Meetings to Rooms and Find the Most-Used One

    Simulate meetings being placed into n numbered rooms, delaying them when all rooms are full, then report the room that hosted the most meetings, preferring the lowest index on ties.

    Heaps, Sorting & Searchheapsimulationpriority-queueintervals
  • Heaps, Sorting & SearchMediumModel answer
    Top Words in a Huge Text File Under Tight Memory

    Count word frequencies in a text file far larger than RAM, with explicit tokenization rules and an efficient exact top-K, and analyze time, memory and disk costs.

    Heaps, Sorting & Searchword-countstreamingexternal-memorytop-k
  • Math & Bit ManipulationMediumModel answer
    Runners Dodging Bouncing Sentries Along a Track

    Count how many runners, released one per time unit, cross a track without ever sharing a cell at the same integer time with a sentry that bounces back and forth inside a fixed range.

    Math & Bit Manipulationsimulationmodular-arithmeticperiodic-motionparity
  • Math & Bit ManipulationEasyModel answer
    Invert Bit at Specific Index

    Invert the bit at a given index in a non-negative integer using bitwise operations.

    Math & Bit Manipulationmath-bitsbit-manipulationmath
  • Arrays & HashingMediumModel answer
    Weighted Random Index Sampling and Exclusion Product Array

    Implement weighted index sampling with binary search and an exclusion product array without division in O(1) auxiliary space.

    Arrays & Hashingarraysbinary-searchprefix-sum
  • Data Structure DesignMediumModel answer
    Turn-Based Squad Combat Engine with Deterministic Ordering

    Simulate a fight between two squads of monsters with fixed turn order, weakest-first targeting and a damage formula, and return the ordered list of attack events.

    Data Structure Designsimulationobject-oriented-designsortingtie-breaking