Search across blog, articles, projects, courses, and community posts
Given a list of intervals, merge every pair that overlaps or touches, and print the result sorted by start. Intervals [1, 4] and [4, 5] touch at 4, so they merge into [1, 5].
Input:
n, the number of intervals.n lines start end (start <= end), in any order.Output: the merged intervals, one start end per line, sorted by start.
1 <= n <= 200, values between 0 and 10^6.
4 1 3 2 6 8 10 15 18
1 6 8 10 15 18
2 1 4 4 5
1 5