You are given k lists of integers, each sorted in non-decreasing order. Find the smallest range [a, b] that includes at least one number from each of the k lists.
A range [a, b] is smaller than another range [c, d] if b - a is smaller than d - c, or if the widths are equal and a is smaller than c.
Return the smallest such range as a two-element list.
Example 1
Input: nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]
Output: [20,24]
24 comes from the first list, 20 from the second, and 22 from the third. The range [20,24] has width 4 and no narrower range covers all three lists.
Example 2
Input: nums = [[1,2,3],[1,2,3],[1,2,3]]
Output: [1,1]
The value 1 exists in every list, so the range [1,1] of width 0 already covers all lists.
Constraints
nums.length == k1 <= k <= 35001 <= nums[i].length <= 50-10^5 <= nums[i][j] <= 10^5Each nums[i] is sorted in non-decreasing orderSee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI