Narrowest Window That Touches Every Schedule
Implement narrowestWindow
Several teams each publish a sorted list of available time slots. Find the narrowest window [lo, hi] that contains at least one slot from every team, where "narrowest" means the smallest hi − lo (ties go to the window with the smaller lo). All teams publish the same number of slots.
Trying every slot as a left edge and re-scanning each team's list works but repeats a lot of work. Instead, keep a min-heap holding one current slot per team: the heap root is always the left edge of the best window still possible, and the largest current slot is its right edge. Advancing only the team that owns the smallest slot shrinks the window step by step.
Example 1:
Input: schedules = [[2,9,15],[4,7,20],[6,8,11]]
Output: [7,9]
Example 2:
Input: schedules = [[3,5,8]]
Output: [3,3]
Example 3:
Input: schedules = [[7],[3],[9]]
Output: [3,9]
+ 10 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ schedules.length ≤ 5, and every schedule has the same length, 1 ≤ schedules[i].length ≤ 6 - ●
-50 ≤ schedules[i][j] ≤ 50, and every schedule is sorted in non-decreasing order - ●
Return [lo, hi], the narrowest window with at least one value from every schedule inside it (lo ≤ value ≤ hi); "narrowest" means the smallest hi − lo - ●
If several windows are equally narrow, return the one with the smaller lo
schedules =