intervals
array based on the start of each interval.merged
to keep track of the merged intervals.merged
list is empty or the current interval does not overlap with the last interval in merged
, append it to merged
.
b. If the current interval overlaps with the last interval in merged
, merge them by updating the end of the last interval in merged
to be the maximum of the two interval ends.merged
list.