Merge k Sorted Lists and the Smallest Covering Range

medium
Unit 13 · Heaps & Binary Search0/3 to milestone

Implement with a heap:

  • merge_k(lists): merge k sorted lists into one sorted list in O(N log k)
  • kth_smallest(lists, k): the k-th smallest (1-based) element across all lists, popping only k times
  • smallest_range(lists): the smallest range [lo, hi] that includes at least one number from every list. Compare ranges by width hi - lo, and break ties by the smaller lo. Keep one pointer per list in a min-heap, track the current maximum, and advance the list that holds the minimum.
#heaps#sorting#merging2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Merge k Sorted Lists and the Smallest Covering Range · TechGradify