Python interview question: merge overlapping intervals
Problem
shifts holds a store’s courier shifts [start, end] in hours from the start of the week, in any order. Merge overlapping and touching shifts and return the covered intervals sorted by start, or an empty list if there are no shifts.
def merge_shifts(shifts: list[list[int]]) -> list[list[int]]:
Example
shifts = [[18, 21], [9, 12], [21, 23], [11, 15]] → [[9, 15], [18, 23]]18–21 and 21–23 only touch, but merge too
Solve it free
Checked against hidden tests, right in your browser. No sign-up needed.