Skip to content
C

Merge Overlapping Intervals

Mediumjavapythonccppjavascript

Given a collection of intervals, merge all intervals that overlap or touch, and print the result sorted by start value.

Input Format

The first line contains an integer N, the number of intervals. Each of the next N lines contains two integers start and end (start <= end).

Output Format

Print the merged intervals, one per line as start end, in increasing order of start.

Input (stdin)

Output

Run your code to see output here...