k integer lists lists, each sorted in non-decreasing order. Find a range [a, b] that contains at least one number from every list and return it as [a, b].
Range [a, b] beats range [c, d] if b − a < d − c, or if the lengths are equal and a < c. Return the best qualifying range.lists=[[1, 8, 20], [4, 9], [7, 30]] → [7, 9]
The range [7, 9] contains 8 from the first list, 9 from the second and 7 from the third. No shorter range works.
lists=[[2, 6], [3, 5]] → [2, 3]
Both [2, 3] and [5, 6] work and have length 1. On a tie, the one that starts earlier wins.
lists=[[5], [5, 5], [-1, 5]] → [5, 5]
k = len(lists) ≤ 3500lists[i]) ≤ 50lists[i][j] ≤ 10⁵lists[i] is sorted in non-decreasing orderlists=[[1, 8, 20], [4, 9], [7, 30]]
[7, 9]
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.