I have a list of closed intervals sorted in ascending order by the left bound.
For example, [Interval(1,2), Interval(1,5)]. There is no sorting by right bouns, so [Interval(1,5), Interval(1,2)] is also possible.
I want to get list of disjoint closed intervals. For example, [Interval(1,2), Interval(1,5), Interval(2,3)] should become [Interval(1,2), Interval(2,3), Interval(3,5)] (again sorted by the left bound).
What is the best way to do it? Will the problem become harder if the list is unsorted?
Thank you.