Smallest Range Covering Elements from K Lists
You have k lists of sorted integers. Find the smallest range that includes at least one number from each of the k lists.

30:00

Smallest Range Covering Elements from K Lists
hard
Topics
Companies

You have k lists of sorted integers. Find the smallest range that includes at least one number from each of the k lists.

Example 1:
Input: {"nums":[[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]}
Output: [20, 24]
Constraints:
  • nums.length==k\text{nums.length} == k

  • 1k35001 \leq k \leq 3500

  • 1nums[i].length501 \leq \text{nums}[i].\text{length} \leq 50

  • 105nums[i][j]105-10^5 \leq \text{nums}[i][j] \leq 10^5

  • nums[i] is sorted in non-decreasing order.

Input
arr ={"nums":[[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]}

Initialize heap with first elements. Range: [0, 5]

K Sorted Lists
L0

4

10

15

24

26

L1

0

9

12

20

L2

5

18

22

30

Current Range

[0, 5]

size: 5
Best Range

[0, 5]

size: 5
Lists: 3
Variables
No variables to display
DepthFunction Call
Stack empty
0/10