#C14748. Merge Overlapping Time Intervals
Merge Overlapping Time Intervals
Merge Overlapping Time Intervals
You are given a list of time intervals in \(HH:MM\) format. Your task is to merge all overlapping intervals and output the consolidated intervals in sorted order.
The input starts with an integer \(N\) specifying the number of intervals. Each of the following \(N\) lines contains two time strings, the start time and the end time of an interval, separated by a space.
Two intervals \((s_1, e_1)\) and \((s_2, e_2)\) are said to overlap if \(e_1 \ge s_2\). In such a case, they are merged into a single interval \((s_1, \max(e_1, e_2))\). All times are given in \(HH:MM\) format.
Output the merged intervals, one per line, with the start and end times separated by a space.
inputFormat
The first line contains an integer \(N\) denoting the number of intervals.
The next \(N\) lines each contain two strings in \(HH:MM\) format (separated by a space) representing the start time and the end time of an interval.
outputFormat
Print the merged time intervals, one per line. Each line should contain two time strings separated by a space representing the merged interval in \(HH:MM\) format.
## sample4
09:00 11:00
11:00 12:00
10:30 13:00
15:00 16:30
09:00 13:00
15:00 16:30
</p>