Problem. Given a list of intervals [start, end], merge every group of overlapping intervals and return the disjoint result.
Intervals that touch (one ends where the next starts) also merge.
[[1, 3], [2, 6], [8, 10], [15, 18]] → [[1, 6], [8, 10], [15, 18]]
[[1, 4], [4, 5]] → [[1, 5]]
[[5, 7], [1, 2], [2, 4]] → [[1, 4], [5, 7]] (input isn't sorted)
Unsorted, an interval can overlap anything anywhere in the list. Sorted by start, an interval can only overlap the one you're currently building: everything earlier ended before it, or was already merged into the current one. That's the greedy insight: sort, then sweep left to right, extending the current interval or starting a new one.
ML context. Interval merging cleans up any detector that outputs time ranges: speech segments from voice activity detection, events in logs, highlighted spans in documents, GPU busy periods in a profiler. Real detections come in fragments with tiny gaps, so the ML version merges intervals separated by less than a gap tolerance and drops ones that are too short (Change D).