Write a Python function that merges overlapping intervals, then explain its time complexity in two sentences. ```python def merge_intervals(intervals): if not intervals: return [] intervals = sorted(intervals, key=lambda x: x[0]) merged = [list(intervals[0])] for start, end in intervals[1:]: if start <= merged[-1][1]: merged[-1][1] = max(merged[-1][1], end) else: merged.append([start, end]) return [tuple(pair) for pair in merged] ``` The sort costs O(n log n), and the single pass over the sorted intervals costs O(n), so the total time complexity is O(n log n). Space complexity is O(n) for the sorted copy and the output list.