KatInterview

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

Coding Interview Problems

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

5978
Problems
2214
Auto-graded
15
Topics
272
Added today

Showing 181–210 of 650 results

  • Data Structure DesignMediumModel answer
    Trailing-Day Campaign CTR over Two Skewed Event Feeds

    Build a generator that emits per-campaign impression, click and CTR figures over a trailing 24-hour window, counting one click per impression and accepting events up to 10 minutes late.

    Data Structure Designstreamingsliding-windowheaphash-map
  • Data Structure DesignMediumModel answer
    Proportional Random Index Picker with Fast Repeated Queries

    Design a class that returns a random index with probability proportional to its weight, optimized for many repeated draws after one-time setup.

    Data Structure Designprefix-sumsbinary-searchrandom-samplingfenwick-tree
  • Data Structure DesignMediumModel answer
    Const Pointer Variants and Choosing Between Tree and Hash Maps in C++

    Explain how const placement changes pointer and pointee mutability in C++, then compare std::map and std::unordered_map on structure, complexity, ordering, key needs and use cases.

    Data Structure Designcppconst-correctnesspointersstd-map
  • Data Structure DesignHardModel answer
    Build a Jungle Board Game Engine with Class Hierarchies

    Design the classes for a two-player Jungle (Dou Shou Qi) engine: eight animals, a 9x7 board with water, traps and dens, capture and jump rules, a small API, and tests.

    Data Structure Designobject-oriented-designgame-enginepolymorphismclass-design
  • Data Structure DesignMediumModel answer
    Build a Keyed Task Dispatcher with Global Concurrency Cap

    Design a component that runs tasks in strict order per key, lets different keys run in parallel up to a global limit, and stays correct under concurrent submits and task failures.

    Data Structure Designconcurrencythread-safetyexecutorqueues
  • Dynamic ProgrammingMediumModel answer
    0/1 to Bounded Knapsack Optimization and Traceback

    Solve the 0/1 knapsack problem with optimal item selection, optimize its space complexity, and extend the solution to bounded knapsacks efficiently.

    Dynamic Programmingdynamic-programmingarrayssliding-windowknapsack
  • Trees & GraphsHardModel answer
    Evaluate Chained Sum Definitions with Error Detection

    Compute the integer value of every variable defined as a sum of literals and other variables, raising distinct errors for duplicate, undefined, or circular definitions.

    Trees & Graphstopological-sortgraphkahn-algorithmcycle-detection
  • Math & Bit ManipulationMediumModel answer
    Spot Hidden Differences Between Two Array Routines

    Decide whether two array-processing routines behave identically under 32-bit integer rules, find a smallest counterexample if not, and design tests that expose subtle divergences.

    Math & Bit Manipulationprogram-equivalenceinteger-overflowproperty-based-testingdifferential-testing
  • Data Structure DesignMediumModel answer
    Random Equipment Lending Pool with Constant-Time Operations

    Build an in-memory pool that lends out a uniformly random free item to a borrower, accepts returns, and allows retirement of idle items, with every operation in O(1) average time.

    Data Structure Designhash-maprandomizedswap-and-popinsert-delete-getrandom
  • Heaps, Sorting & SearchMediumModel answer
    Random Index Selection by Given Weights

    Design an index sampler where each element's probability of being chosen is proportional to its assigned weight.

    Heaps, Sorting & Searchprefix-sumbinary-searchrandomizationdata-structure-design
  • Math & Bit ManipulationEasyModel answer
    Two Islanders, One Accusation: Which Role Pairs Work?

    One islander accuses the other of always lying. Test all four role pairings and decide which ones are logically possible.

    Math & Bit Manipulationlogicpuzzlecase-analysisknights-and-knaves
  • Arrays & HashingMediumModel answer
    Best Single Trade Within a Limited Holding Period

    Find the most profitable buy-then-sell pair in a price array when the sale must happen within D days of the purchase, in O(n) time and O(1) extra space.

    Arrays & Hashingsliding-windowblock-decompositionmonotonic-dequestock-trading
  • Trees & GraphsMediumModel answer
    Repairing a Search Tree After One Pair of Keys Trades Places

    Two keys in a binary search tree were exchanged by mistake. Restore ordering by swapping values back, keeping the shape intact, in linear time and constant extra space.

    Trees & Graphsbinary-search-treemorris-traversalin-ordertree-recovery
  • Data Structure DesignMediumModel answer
    Design a Phone-Style Calculator in the Browser

    Build a four-function calculator UI with immediate-execution semantics, tricky key sequences handled correctly, and a layout close to a familiar mobile calculator.

    Data Structure Designstate-machinefrontendjavascriptedge-cases
  • StringsMediumModel answer
    Filter Words Reachable From a Target by One Character Swap

    Given a target string and a list of words, return every word that becomes the target after swapping at most one pair of characters in that word, keeping input order.

    Stringsstringstwo-pointerscharacter-frequencybuddy-strings
  • Data Structure DesignEasyModel answer
    Log a Button's Label on Click with the DOM Event API

    Wire up a click handler on a page button that logs its label to the console, and explain what the event object's target property refers to, including nested-element cases.

    Data Structure Designjavascriptdomevent-handlingfrontend-fundamentals
  • 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
  • Data Structure DesignEasyModel answer
    Immutable Folder Tree State with Safe Move and Delete

    Design a normalized, immutable state model for a nested folder tree and implement add, move (with cycle rejection) and recursive delete efficiently for deep trees.

    Data Structure Designtreestate-managementimmutabilitycycle-detection
  • Data Structure DesignMediumModel answer
    Task Scheduling Order and Undoable Command Pipeline

    Resolve prerequisite-constrained task sequences with cycle detection, then construct an extensible Command pattern system with state rollback functionality.

    Data Structure Designtrees-graphsdesign-dsstacks-queues
  • Data Structure DesignHardModel answer
    Blocking Bounded Buffer for Many Producers and Consumers

    Design and code a fixed-capacity, multi-producer multi-consumer buffer with timed blocking put/get, fair waiter ordering, clean shutdown and backpressure, and explain how you would test it.

    Data Structure Designconcurrencysynchronizationcondition-variablesbackpressure
  • Data Structure DesignHardModel answer
    Distributed Block Matrix Multiplication via Cannon's Algorithm

    Coordinate grid-based worker nodes to perform memory-efficient distributed matrix multiplication without deadlocks.

    Data Structure Designdistributed systemsmatrix multiplicationconcurrencyalgorithms
  • Data Structure DesignMediumModel answer
    Layered Ledger Service: Cash, Transfers, Fees and Held Funds

    Design and code a bank ledger that grows in stages: cash operations, per-account statements with failures, internal and external transfers with fees, and delayed transfers that lock funds.

    Data Structure Designledgermoney-handlingobject-oriented-designtransactions
  • Dynamic ProgrammingMediumModel answer
    Cheapest Fence Painting With No Matching Neighbors

    Color a row of posts from a cost table so no two neighbors match, minimizing total cost, using memoized recursion and a space-optimized bottom-up DP, and recover one optimal coloring.

    Dynamic Programmingdynamic-programmingmemoizationspace-optimizationreconstruction
  • Trees & GraphsMediumModel answer
    Minimum Additions to Equalize Every Subtree Sum

    Calculate the minimum non-negative value additions needed so that the node sum of every subtree in a binary tree equals K, returning -1 if impossible.

    Trees & Graphstrees-graphspost-ordergreedydepth-first-search
  • StringsMediumModel answer
    Linked-Field Payment Card Form with Live Validation

    Build a browser payment card form where the detected card network drives number formatting, length checks and security-code rules, with validation and a submit callback.

    Stringsfrontendform-validationluhninput-formatting
  • Math & Bit ManipulationMediumModel answer
    Simulate 2048 Mechanics and Pack Grid into 64-Bit Integer

    Simulate grid sliding and merging rules for the game 2048, and design a bit-packing scheme to compress the 4x4 state into a single 64-bit integer.

    Math & Bit Manipulationbit-manipulationarrayssimulationmatrix
  • Data Structure DesignMediumModel answer
    Build an In-Memory Ledger with Delayed Rewards and Account Merging

    Design an in-memory ledger that handles idempotent transfers, top-k senders, rewards posted 24 hours after a purchase, and account merging, and explain how you would test and scale it.

    Data Structure Designdesignhash-mapheapidempotency
  • Data Structure DesignMediumModel answer
    Ad Campaign Event Aggregator with Pluggable Event Types

    Design an object-oriented component that ingests ad events and returns windowed per-campaign metric sums and ratios, while letting new event types be added without editing core code.

    Data Structure Designobject-oriented-designtime-seriesprefix-sumsbinary-search
  • Trees & GraphsMediumModel answer
    Same-Host Link Crawler: Sequential and Concurrent Versions

    Crawl every page reachable from a seed URL on the same host, ignoring URL fragments, first with one thread and then with a thread-safe parallel design.

    Trees & Graphsbfsgraph-traversalconcurrencythread-pool
  • Arrays & HashingMediumModel answer
    Code Review Drill: Three Pandas Helpers in a Data Pipeline

    Explain what three short pandas helper functions do, then propose and justify improvements to their correctness, speed, readability, robustness and testability.

    Arrays & Hashingpythonpandascode-reviewvectorization