#C641. Finding Free Time Periods Between Appointments
Finding Free Time Periods Between Appointments
Finding Free Time Periods Between Appointments
You are given a list of appointments where each appointment is represented by a start date and an end date in the format (YYYY-MM-DD). Appointments may overlap or be consecutive. Your task is to determine all the free time periods between these appointments. A free period exists when there is at least one day that is not covered by any appointment. In particular, if the gap between the end date of one appointment and the start date of the next appointment is greater than one day, then the free period starts on the day immediately after the previous appointment's end and ends on the day immediately before the next appointment's start. For example, if an appointment ends on (d_1) and the next appointment starts on (d_2) where (d_2 \ge d_1+2), then the free period is from (d_1+1) to (d_2-1) (both inclusive).
inputFormat
The input is read from standard input. The first line contains an integer (n) representing the number of appointments. Each of the following (n) lines contains two space-separated strings representing the start and end dates of an appointment in the format (YYYY-MM-DD). Note: (n) can be zero, in which case there are no appointments.
outputFormat
Output the free periods, each on a separate line. For each free period, print two dates (start and end of the free period) separated by a single space. If no free period exists, output nothing.## sample
2
2023-01-01 2023-01-05
2023-01-05 2023-01-10