Skip to the code
cf.
+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 <= 3000
  • 1 <= lists[i].length <= 50
  • -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 solves the problem when they all pass.

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