← 返回 jpmorgan 的题目列表Merge Intervals
类型:online_judge
Problem: Merge Intervals
Given an array of intervals intervals, where intervals[i] = [start_i, end_i], merge all overlapping intervals and return a non-overlapping interval array that covers all intervals in the input.
Intervals that touch at endpoints, such as [1, 4] and [4, 5], should also be merged into [1, 5].
Input Format
First line: integer n, the number of intervals
Next n lines: two integers start end
Output Format
Print each merged interval as start end
Output intervals in ascending order of start time
Constraints
1 <= n <= 10^4
0 <= start <= end <= 10^9
Example
Input:
4
1 3
2 6
8 10
15 18
Output:
1 6
8 10
15 18
Example
Input
4
1 3
2 6
8 10
15 18
Output
1 6
8 10
15 18