Practice · 3 of 5
Merged Intervals
CHALLENGE
Difficulty: beginner+25 XP
**Description:** Given n intervals [l_i, r_i], merge all overlapping or
touching intervals and print the merged intervals sorted by start.
**Input:** Line 1: n (1 <= n <= 10^5). Next n lines: l r (0 <= l <= r <= 10^9).
**Output:** Each merged interval on its own line: l r.
**Example:** 4 / 1 3 / 2 6 / 8 10 / 15 18 -> 1 6 / 8 10 / 15 18.
Press Submit to check your solution.
Back to lesson: Practice: Sorting Set