#632

Smallest Range Covering Elements from K Lists

specialist · 990 · lc hard +32 · verified · 70.1% accepted · 4,386 likes · top 78%

play →

Description

Given k sorted lists of integers, find the smallest interval [a, b] that contains at least one element from every list. An interval [a, b] is considered smaller than [c, d] if its length is shorter, or if lengths are equal, if a < c.

Example 1:

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].

Example 2:

Input: nums = [[1,2,3],[1,2,3],[1,2,3]]
Output: [1,1]

Code

1
2
3