Dsa
Intervals
Medium
Interval Merge Problem
You have been assigned to clean up a list of time intervals that may overlap and need merging. Given a list of intervals represented by their start and end times, your task is to merge all overlapping intervals and print them in sorted order. Each interval is given in the format "start end". You should read the list of intervals and output the merged intervals in the same format.
Input Format:
- The first line contains an integer n, the number of intervals (1 <= n <= 1000).
- The next n lines contain two integers for each interval's start and end.
Output Format:
- Print the merged intervals in the format "start end", each on a new line.
Example:
Input:
5
1 3
2 4
5 7
6 8
9 10
Output:
1 4
5 8
9 10
Key concepts
intervalssortingmerging
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now