KatInterview

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

Heaps, Sorting & Search Interview Problems

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

5965
Problems
2208
Auto-graded
15
Topics
271
Added today

Showing 1–30 of 31 results

  • 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
  • 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
  • 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
  • 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
  • Heaps, Sorting & SearchMediumModel answer
    Ordering a Hundred Million Decimal Digits in Place

    Order a huge byte array holding only the values 0 to 9 in linear time with constant extra memory, then reason about storage layout, memory bandwidth and expected runtime.

    Heaps, Sorting & Searchcounting-sortin-placememory-bandwidthbytearray
  • Heaps, Sorting & SearchMediumModel answer
    Batched API Delivery with Delay-Aware Retries

    Deliver a list of requests through an API capped at five per call, retrying failures only after each request's own cooldown, without busy-waiting or blocking on one failure.

    Heaps, Sorting & Searchbatchingretryschedulingpriority-queue
  • Heaps, Sorting & SearchMediumModel answer
    Fill Spare Slots and Sort One Buffer In Place

    Combine two unsorted integer lists into the first, which has spare room at its end, so it ends up fully ascending, without using placeholder values to locate the data.

    Heaps, Sorting & Searcharrayssortingin-placeheapsort
  • Heaps, Sorting & SearchMediumModel answer
    Exact Mode, Median and Balanced Sort Over Ten Message-Passing Nodes

    Integers live on ten machines that can only exchange messages. Write per-node programs for the exact mode, the median and a balanced global sort while sending as little data as possible.

    Heaps, Sorting & Searchdistributed-systemsmapreducesample-sortselection
  • Heaps, Sorting & SearchMediumModel answer
    Quicksort vs Mergesort: Hardware, Stability and Disk Trade-offs

    Compare two O(n log n) sorts by how they use caches, preserve tie order, resist bad inputs, and behave when data lives on disk instead of in memory.

    Heaps, Sorting & Searchquicksortmergesortstabilitycache-locality
  • Heaps, Sorting & SearchMediumModel answer
    Two-Sided Order Book Matching with Unit Orders

    Simulate a simple exchange: buys and sells of size one arrive in sequence, cross against the best resting price, and you return the total value of all executed trades.

    Heaps, Sorting & Searchheappriority-queuesimulationorder-book
  • 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
  • Heaps, Sorting & SearchMediumModel answer
    Design a Single-Threaded Delayed Task Runner

    Implement a priority-queue task runner that handles delayed execution without busy-waiting.

    Heaps, Sorting & Searchheappriority-queuedesign-dstime-complexity
  • Heaps, Sorting & SearchMediumModel answer
    Design and Analyze an Intentionally Inefficient Correct Sorting Algorithm

    Propose a fully correct yet highly inefficient sorting algorithm, prove its termination and correctness, and derive its time and space complexity.

    Heaps, Sorting & Searchsortingcomplexity-analysiscombinatoricsrecursion
  • Heaps, Sorting & SearchMediumModel answer
    Find Frequent Elements in Large-Scale Data Streams

    Design scalable algorithms to extract the top K most frequent elements from a data stream under both memory-bounded exact and memory-constrained approximate regimes.

    Heaps, Sorting & Searchheaps-sortingdesign-dsarrays
  • Heaps, Sorting & SearchMediumModel answer
    Minimize Black-Box Unimodal Function Without Derivatives

    Find the minimum of a convex/unimodal function over continuous and discrete intervals using zero-order optimization.

    Heaps, Sorting & Searchbinary searchoptimizationunimodalgolden section
  • Heaps, Sorting & SearchMediumModel answer
    Streaming Word Frequencies from an Oversized Text File

    Build a memory-safe word counter for a huge text file, define tokenization rules, return the top-k words deterministically, and discuss what to do when the vocabulary strains memory.

    Heaps, Sorting & Searchword-countstreaminghash-maptop-k
  • Heaps, Sorting & SearchMediumModel answer
    Batched Notification Sender with Cooldown-Aware Retries

    Push messages through a provider that accepts at most 5 per call, and retry each failure only after its own cooldown expires, with an attempt cap and no busy-waiting.

    Heaps, Sorting & Searchbatchingpriority-queueretry-schedulingmin-heap
  • Heaps, Sorting & SearchMediumModel answer
    Cost of Core Data Structure Ops and When Threads Hurt

    Give worst-case Big-O for four common array, hash table and heap operations, then explain why adding threads does not always speed a program up, with concrete counterexamples.

    Heaps, Sorting & Searchbig-ohash-tableheapmultithreading
  • Heaps, Sorting & SearchMediumModel answer
    Fixed-Width Window Totals and Rolling Median Over a Stream

    Find the best sum over any run of k adjacent numbers, then track the median of the latest k values in a live stream, discussing data structures, parallelism and trade-offs.

    Heaps, Sorting & Searchsliding-windowtwo-heapsmedianlazy-deletion
  • Heaps, Sorting & SearchMediumModel answer
    Minimum-Distance Depot Placement on a Grid with Blocked Cells

    Place a depot on a 2D integer grid to minimize total Manhattan distance to all warehouses, avoiding any cell occupied by an obstacle.

    Heaps, Sorting & Searchmanhattan-distancemedianpriority-queueprefix-sums
  • Heaps, Sorting & SearchHardModel answer
    Identify Hidden Conflict with Minimal Oracle Queries

    Find one conflicting pair among n items using a black-box oracle that tests subsets, minimizing the number of expensive queries.

    Heaps, Sorting & Searchbinary-searchoptimizationoracleinformation-theory
  • Heaps, Sorting & SearchHardModel answer
    Rolling Window Median Bounds + Binary Array Tiling

    Find the max and min sliding-window medians in O(n log k), then partition a binary array into even uniform segments with minimum flips.

    Heaps, Sorting & Searchsliding windowheapdynamic programmingbinary array
  • Heaps, Sorting & SearchHardModel answer
    Locate Local Minima Using Divide-and-Conquer

    Implement sublinear algorithms to identify a local minimum in a 1D array and a 2D grid by applying binary search to unimodal descent.

    Heaps, Sorting & Searchbinary-searchdivide-and-conqueralgorithms
  • Heaps, Sorting & SearchHardModel answer
    Binary Search with Delayed Feedback Protocol

    Find a hidden number using binary search when each query returns the result of your previous guess instead of your current one.

    Heaps, Sorting & Searchbinary-searchalgorithmsfeedback-systems
  • Heaps, Sorting & SearchMediumModel answer
    Streaming Weighted Reservoir Sampling Without Replacement

    Implement a single-pass, memory-efficient weighted sampler that draws k distinct items proportional to weight from a potentially huge stream.

    Heaps, Sorting & Searchreservoir-samplingprobabilitynumerical-stabilityheap
  • Heaps, Sorting & SearchMediumModel answer
    Budget-Constrained Selection and Graph Distance Query

    Find how many sorted items fit within a budget using prefix sums and binary search, then parse a graph and compute the shortest path between two nodes.

    Heaps, Sorting & Searchbinary-searchdijkstraprefix-sumshortest-path
  • Heaps, Sorting & SearchMediumModel answer
    Optimal Order Fulfillment with Decaying Prices

    Determine the maximum revenue when fulfilling orders from inventory where each item's price equals its current stock level and decreases with each sale.

    Heaps, Sorting & Searchbinary-searchgreedymathpriority-queue
  • Heaps, Sorting & SearchMediumModel answer
    Binary Search Optimization and Interval Consolidation

    Find the minimal rate to process items within a time limit, then consolidate overlapping ranges into non-overlapping spans.

    Heaps, Sorting & Searchbinary-searchintervalsgreedyoptimization