15% off all plans & roadmaps Use code
See plansLeetCode 632 · Solution & editorial
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.
Smallest Range Covering Elements from K Lists is a Heap (Priority Queue) Patterns problem, in the K-way Merge subpattern. The pattern covers top K elements, K-way merge, two heaps for median, and scheduling
Master K-way merge pattern using min heap. Merge k sorted lists and find kth smallest in matrix.
The reference solution runs in O(N log k) time and O(k) space.
Smallest Range Covering Elements from K Lists has been reported in interviews at Amazon.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Smallest Range Covering Elements from K Lists is a Heap (Priority Queue) Patterns problem, in the K-way Merge subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.