One simple solution is to compare each interval with every other interval in the list, and merge any overlapping intervals. However, the time complexity of this algorithm is O(n^{2}), where n is the number of intervals.

A better algorithm follows:

Sort the list of intervals, based on the start time of each interval.

Perform linear scan and merge any overlapping adjacent intervals.

Because we have to sort, the time complexity of this algorithm is O(n log n), where n is the number of intervals.

A Java implementation of the second algorithm follows. The IntervalComp class is a Comparator used for sorting.