You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists.
We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.
Input: nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]
Output: [20,24]
Explanation:
List 1: [4, 10, 15, 24,26], 24 is in range [20,24].
List 2: [0, 9, 12, 20], 20 is in range [20,24].
List 3: [5, 18, 22, 30], 22 is in range [20,24].
Input: nums = [[1,2,3],[1,2,3],[1,2,3]]
Output: [1,1]
The problem requires finding the smallest range that includes at least one number from each of K lists. We can use a min-heap to efficiently track the smallest current number across all lists and try to widen our range by tracking maximum elements simultaneously.
By flattening all lists into a single sorted list while keeping track of their origins, we can use a two-pointer technique to identify the smallest range covering all lists.