#C6905. Merge Overlapping Intervals
Merge Overlapping Intervals
Merge Overlapping Intervals
You are given a collection of intervals. Each interval is represented as a pair of integers [start, end) where start is inclusive and end is exclusive. Your task is to merge all overlapping intervals and output the resulting intervals in sorted order.
Two intervals \([a, b)\) and \([c, d)\) are considered overlapping if they satisfy the condition $$ c \leq b $$.
For example, merging intervals [[1,3],[2,6],[8,10],[15,18]] results in [[1,6],[8,10],[15,18]].
Please note: You must handle the input from stdin
and output the result to stdout
.
inputFormat
The first line of input contains a single integer \(T\) representing the number of intervals. Each of the following \(T\) lines contains two space-separated integers representing the start and end of an interval.
Example:
4 1 3 2 6 8 10 15 18
outputFormat
Output the merged intervals in sorted order, one interval per line. Each line should contain two space-separated integers representing the start and end of that merged interval.
Example:
1 6 8 10 15 18## sample
4
1 3
2 6
8 10
15 18
1 6
8 10
15 18
</p>