#632

Smallest Range Covering Elements from K Lists

Hard Min-heap with running max

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Given k sorted lists, find the smallest range [a, b] that includes at least one number from each list (ties: the one with the smaller a).

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: the narrowest range containing at least one number from every list.

Why this works: hold one pointer per list. The range is [min, max] of the pointed values; only advancing the list with the minimum can make it narrower.

Example: [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]

start {4, 0, 5} → [0, 5]… best found [20, 24]

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Advancing the list with the maximum — that can only widen the range.

Solve on LeetCode ↗
Complexity
  • Time: O(N log k), N = total elements.
  • Space: O(k).
Topic: Heaps & Priority Queue
🎬 Episodes 64–68: video coming soon