425. Insert Interval
MediumIntervals
You are given sorted, non-overlapping intervals and one new interval. Insert it and merge overlaps (touching intervals like [1,5] and [5,7] merge). Print the result, one interval per line.
Input format
Line 1: n Next n lines: start end Last line: the new interval
Output format
One "start end" per line.
Example 1
Input
2 1 3 6 9 2 5
Output
1 5 6 9
Example 2
Input
5 1 2 3 5 6 7 8 10 12 16 4 8
Output
1 2 3 10 12 16
Constraints
0 ≤ n ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…