Interval merge for maintenance windows
Python data engineering interview problem. Difficulty: advanced. Pattern: Sorting. About 20 minutes. Part of the Pro drill bank.
Maintenance windows are intervals on a timeline. Overlapping windows should merge so the calendar shows one closed period instead of three stacked ones.
Maintenance windows are recorded as [start, end] pairs and some overlap. Operations wants the smallest list of windows that covers the same time. Merge overlapping windows. Two windows overlap if the next one starts before or at the end of the current one. Return the merged windows, sorted by start. An empty list returns []. Write merge_windows(windows). [[1, 3], [2, 6], [8, 10]] becomes [[1, 6], [8, 10]], because [1, 3] and [2, 6] overlap. An empty list gives []. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Sort windows by start.
- Merge windows that overlap or touch.
- Use the larger end when merging.
- Return [] for no windows.
Constraints
- Each window is [start, end] with start <= end.
- The input may be unsorted.
Examples
Input: merge_windows([[1, 3], [2, 6], [8, 10]]) Output: [[1, 6], [8, 10]] This input follows the stated rules and produces this output.
Topics: lakebench, python, sorting.
More Python interview questions · All interview problems · Learn data engineering
Interval merge for maintenance windows
Interview-style drill: Merge a list of overlapping maintenance time windows into the minimal set of non-overlapping windows.
Merge overlapping maintenance intervals.