Merge overlapping intervals

Write codeMedium14 minMeta style

Your task

A parking app records reservations for one space as [start, end] hour pairs, treated as closed ranges. Reservations that overlap or touch, one ends exactly when another starts, belong to the same continuous occupied block. Given an unsorted list, merge it and return the occupied blocks as [start, end] pairs sorted by start. Example: [[8,10],[1,3],[2,6]] becomes [[1,6],[8,10]].

Examples

merge_reservations(reservations: list[list[int]]) -> list[list[int]]
Example 1
Inputmerge_reservations([[8, 10], [1, 3], [2, 6]])
Output[[1, 6], [8, 10]]