Explain the code which you wrote.
Asked in the Second-round coding interview stage. Asked after the candidate completed the coding portion; the interviewer wanted a walkthrough of the candidate's own solution.
For the coding portion, use def merge_intervals(intervals):. The input is a list of integer [start, end] pairs, and the output is a list of non-overlapping intervals covering the same ranges. Explain the algorithm, correctness, complexity, and edge-case behavior.
def merge_intervals(intervals):