Fix the maintenance lookup for incident reports
Your task
Your status page links each incident to the maintenance that was running when it started. Maintenance windows can overlap, and the most specific explanation is the shortest window that was open.
An assistant wrote shortest_windows(windows, incidents). It is in the editor. It has a bug. Find it and fix it.
Input and output:
windows: pairs[start, end]in whole minutes, in any order. A window is open fromstarttoend, both included, andstartis never afterend.incidents: the minute each incident started, in any order. Two incidents can share a minute.- Return one number per incident, in the order of
incidents: the length of the shortest window open at that minute, counted asend - start + 1, or -1 when no window is open.
Rules the tests check:
- Times are from 0 to 1,000,000,000.
- There are at most 100,000 windows and 100,000 incidents.
Then, in a sentence or two: how would you catch this kind of bug in review?
Examples
shortest_windows(windows: list[list[int]], incidents: list[int]) -> list[int]Example 1
Input
shortest_windows([[60, 120], [90, 100], [200, 260]], [95, 110, 150, 230])Output
[11, 61, -1, 61]Example 2
Input
shortest_windows([[0, 1000], [100, 300], [150, 200]], [180, 250, 900, 1001])Output
[51, 201, 1001, -1]Example 3
Input
shortest_windows([], [5, 6])Output
[-1, -1]