Skip to the code
+50 XP

#392 Smallest Window Covering Every Feed

hard

A monitoring tool has several sorted lists of event timestamps, one per service. To show a single time window where every service did something, it needs the shortest range [lo, hi] that contains at least one timestamp from every list.

Write coveringRange(lists) that returns that range as [lo, hi]. A range [a, b] is better than [c, d] if b - a < d - c, or if the widths are equal and a < c. Every list is sorted ascending and non-empty.

Example 1

Input: lists = [[1,10,20],[8,15],[12,30]]
Output: [8,12]

10, 8, and 12 are all inside [8, 12], width 4. No narrower range covers all three lists.

Example 2

Input: lists = [[5],[5],[5]]
Output: [5,5]

All lists share 5, so the width is 0.

Constraints

  • 1 <= lists.length <= 10^5
  • 1 <= lists[i].length <= 50
  • All lists together hold at most 2 * 10^5 values.
  • -10^5 <= value <= 10^5
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).