Dsa
Intervals
Hard
Merger Overlap
You are given a list of intervals representing time slots in a schedule. Your task is to merge any overlapping intervals and return the combined list of intervals sorted by start time. Each interval is represented as a pair of integers [start, end]. Overlapping intervals are defined as intervals where the start time of one is less than or equal to the end time of another. If there is no overlap, the intervals should remain unchanged.
Input:
The first line contains an integer n (1 ≤ n ≤ 10^5) — the number of intervals.
The next n lines contain two integers each: start and end (1 ≤ start ≤ end ≤ 10^9).
Output:
Print the merged intervals, one per line, each interval on a separate line in the format `[start, end]`. The intervals should be sorted in ascending order of their start time.
Example:
Input:
3
1 3
2 4
5 7
Output:
[1, 4]
[5, 7]
Key concepts
intervalsmergingsorting
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