KatInterview

Topic

Heaps, Sorting & Search interview problems

Priority queues, binary search and custom ordering. 200 original problems, each with hidden test cases you can run in the browser.

Problems200

24 easy163 medium13 hard

Showing 1–30 of 200 results

  • Count element-level comparisons during an adaptive divide-and-conquer merge sort.

    Auto-gradedsortingdivide-and-conquerrecursionarrays
  • Compute the mean of each fixed-size window after discarding its k largest values, which needs a structure that supports fast insertion, deletion and sum-of-smallest queries.

    Auto-gradedsliding-windowfenwick-treeorder-statisticsheaps
  • 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.

    Auto-gradedsortingtuple-keystie-breakingselection
  • Locate a local minimum in an array of integers in logarithmic time while handling flat regions and boundaries.

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

    Model answerbinary searchprefix sumrandom samplingdesign-ds
  • Simulate repeatedly removing the two largest values and reinserting their difference, using a max-heap to find the last remaining value or 0.

    Auto-gradedheappriority-queuesimulation
  • Perform logarithmic-time binary search on a strictly increasing array of distinct integers to find a target value's index or detect its absence.

    Auto-gradedbinary-searcharrayssearching
  • 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.

    Model answersliding-windowheapmedianlazy-deletion
  • 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.

    Model answerheapgreedylinked-liststring
  • 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.

    Model answerheapsimulationpriority-queueintervals
  • 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.

    Model answerword-countstreamingexternal-memorytop-k
  • Use binary search to find the first and last positions of a value in a sorted list in logarithmic time, returning [-1, -1] when it is absent.

    Auto-gradedbinary-searchsorted-arrayboundaries
  • Merge k individually sorted integer arrays into a single sorted array, testing heap-based k-way merging or pairwise divide-and-conquer and the associated complexity analysis.

    Auto-gradedheapk-way-mergedivide-and-conquersorting
  • Simulate placing items one by one into the currently lowest lane, breaking ties by lowest index, and report each lane's final total using a min-heap.

    Auto-gradedheapgreedysimulationpriority-queue
  • Sort scattered points by x, then find the y on the connecting line at a query x, interpolating inside the range and extending the end segments outside it.

    Auto-gradedbinary-searchsortinginterpolationgeometry
  • Apply a quadratic mapping to a sorted list of numbers and return the sorted results in O(n) time.

    Auto-gradedtwo-pointersarraysmath
  • Find the largest integer k such that at least k entries in a list are at least k, testing sorting or counting-based selection and reasoning about monotone thresholds.

    Auto-gradedsortingcountingh-indexarrays
  • Sort a probability list with deterministic tie-breaking, then build two truncated, renormalized versions: fixed-size top-k and cumulative-mass top-p.

    Auto-gradedsortingprefix-sumprobabilityfloating-point
  • Search a cyclically shifted strictly increasing list of distinct integers for a value in O(log n), returning its index or -1, including unshifted and single-element cases.

    Auto-gradedbinary-searcharraysrotated-arraydivide-and-conquer
  • Sort a list of integers in ascending order without mutating the input, using a divide-and-conquer merge approach that guarantees O(n log n) time and linear auxiliary space.

    Auto-gradedsortingdivide-and-conquermerge-sortstability
  • Combines selecting the element at a 0-indexed rank in descending order with a sliding window finding the longest stretch containing at most a given number of workdays.

    Auto-gradedheapsliding-windowtwo-pointersorder-statistics
  • Find all distinct combinations of three elements in an integer sequence that sum to zero using two pointers and duplicate handling.

    Auto-gradedarraystwo-pointerssorting
  • Find the smallest semantic version that satisfies a monotonic compatibility check while minimizing evaluations.

    Auto-gradedbinary-searchsortingarrays
  • Select the K most frequent ad IDs among timestamped impressions in an inclusive window, breaking ties by smaller ID; tests binary search on sorted data plus counting and ordering.

    Auto-gradedbinary-searchhash-mapsortingsliding-window
  • Find the k-th smallest value in an unsorted integer list, counting duplicates, using a linear-time selection idea such as quickselect instead of a full sort.

    Auto-gradedquickselectselectionpartitioningorder-statistics
  • Compute the mean of every fixed-size window after removing its k largest entries, which requires an ordered structure that supports efficient insertion and deletion.

    Auto-gradedsliding-windowheapfenwick-treeorder-statistics
  • Evaluate efficient sorted array lookups for repetitive queries using binary search combined with memoization.

    Auto-gradedbinary-searcharraysmemoizationhashing
  • Evaluate a piecewise linear curve at a query coordinate by locating the right segment with binary search and interpolating, returning None outside the curve's domain.

    Auto-gradedbinary-searchinterpolationarraysedge-cases
  • Find a value's index in a rotated sorted array with binary search, then list the k most frequent values with ties broken by smaller value.

    Auto-gradedbinary-searchrotated-arrayhash-mapfrequency-count
  • Enumerate point pairs in d dimensions, compute the volume of the box they span, drop flat boxes, and return the rest in a strict multi-key order.

    Auto-gradedsortingpair-enumerationgeometrymulti-key-sort

More topics