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 31–60 of 200 results

  • 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.

    Model answercounting-sortin-placememory-bandwidthbytearray
  • Convert an integer list into a max-heap layout using the bottom-up sift-down procedure, matching an exact output array including tie-break behavior.

    Auto-gradedheaparraysift-downin-place
  • Implement a factorial-time sort that tries arrangements until one is non-decreasing, handling duplicates and empty input, and reason about its cost.

    Auto-gradedsortingpermutationsbrute-forcecomplexity-analysis
  • Process raw assessment records by replacing missing marks with course-level medians and return the top 5 performers.

    Auto-gradedsortingdata-cleaninghash-tableaggregations
  • Produce an execution order for jobs with prerequisites by always running the ready job with the earliest deadline, breaking ties by id, using topological sort with a heap.

    Auto-gradedtopological-sortheapgraphpriority-queue
  • Greedy selection with a sorted unlock pointer and a max-heap: repeatedly pick the most profitable venture whose entry threshold fits the current funds, up to a fixed number of picks.

    Auto-gradedheapgreedysortingpriority-queue
  • Find the minimum per-day load limit that moves an ordered list of parcels in at most a given number of days, using binary search on the answer with a greedy feasibility check.

    Auto-gradedbinary-searchgreedysearch-on-answerarrays
  • Tests implementing custom merge sort to sort an array and finding the sorted unique intersection of two lists.

    Auto-gradedsortingmerge-sorthash-setarrays
  • Select the k-th largest value, counting duplicates separately, from an unsorted integer list without a full sort, using quickselect or a bounded heap.

    Auto-gradedquickselectheapselectionpartitioning
  • Computes min, mean, and median robustly for floating-point data, handling missing/invalid values and large magnitude edge cases safely.

    Auto-gradedheaps-sortingarraysmath-bits
  • Process paired operation and value lists, tracking the K largest integers seen so far and recording a descending snapshot after every operation, using a bounded min-heap.

    Auto-gradedheapstreamingtop-kpriority-queue
  • Use parity-based binary search on a sorted array of duplicated values to find the one value without a partner in logarithmic time and constant extra space.

    Auto-gradedbinary-searchsorted-arrayparityarrays
  • Simulate placing blocks one at a time onto the currently lowest of k stacks, with ties going to the lowest index, and report each chosen stack; tests heap-based greedy simulation.

    Auto-gradedheappriority-queuegreedysimulation
  • 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.

    Model answerbatchingretryschedulingpriority-queue
  • Process a series of dynamic data stream queries to compute the median on demand using heap-based structures.

    Auto-gradedheapsheapqdata-structuresdesign-ds
  • Tests merging K nondecreasing integer lists into a single sorted list, preserving duplicates and handling empty lists, using a heap or pairwise merging.

    Auto-gradedheapmergek-way-mergesorting
  • Find the maximum integer segment length that can produce at least a specified count of equal-sized pieces using binary search on answer.

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

    Model answerarrayssortingin-placeheapsort
  • Find the minimum number of negative transactions to postpone so that the running account balance remains non-negative throughout processing.

    Auto-gradedheaps-sortinggreedy-intervalsarrays
  • Find the largest integer segment length such that cutting every spool into equal segments yields at least k segments, using binary search on a monotonic feasibility check.

    Auto-gradedbinary-searchbinary-search-on-answermonotonic-predicatearrays
  • 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.

    Model answerdistributed-systemsmapreducesample-sortselection
  • Simulate FIFO dispatch of tasks to workers with a preference for each account's last worker, using heaps and a lookup table to track free and busy workers.

    Auto-gradedheapsimulationschedulinghash-map
  • Rearrange feed items by sorting on rank score, grouping photos into batches of up to three, and maintaining stable ordering for equal scores.

    Auto-gradedsortingarraysbatching
  • Tests explicit binary search on a sorted array: find a value's index or the position where it would be inserted, in logarithmic time.

    Auto-gradedbinary-searchsorted-arrayarraystwo-pointers
  • Select the k greatest values from an unsorted integer list, duplicates included, returned from largest to smallest, ideally in O(n log k) time using a bounded min-heap.

    Auto-gradedheaptop-ksortingarrays
  • 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.

    Model answerquicksortmergesortstabilitycache-locality
  • Find the k-th smallest value in a two-dimensional grid where every row and column is sorted in ascending order.

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

    Model answerheappriority-queuesimulationorder-book
  • Find the largest integer length such that cutting every rope into pieces of that length yields at least k pieces; tests binary search over a monotonic answer space.

    Auto-gradedbinary-searchbinary-search-on-answermonotonic-predicatearrays
  • Find the tightest inclusive interval that holds at least one value from each of several sorted arrays, using a k-way merge with a min-heap and a tracked maximum.

    Auto-gradedheapk-way-mergesorted-liststwo-pointers

More topics