Merge Maintenance Windows
150 points · 0 solved
The first line is n (1 ≤ n ≤ 2500). Each of the next n lines is start end (0 ≤ start ≤ end ≤ 10⁹), in any order. Merge every pair of windows that overlap or touch (next start ≤ current end) and print the merged windows in ascending order, one start end per line.
Example 1 input
4 1 3 2 6 8 10 10 12
Expected output
1 6 8 12
main.py
Ctrl+Enter runs · Ctrl+Shift+Enter submits