#K94537. Message Duration Calculation
Message Duration Calculation
Message Duration Calculation
You are given multiple test cases. Each test case consists of a list of timestamps in the format YYYY-MM-DD HH:MM:SS. Your task is to calculate the total duration in seconds between the earliest and the latest timestamp in each test case.
The duration is computed using the formula:
\(\text{duration} = \text{max_timestamp} - \text{min_timestamp}\)
If a test case contains no timestamps or only one timestamp, the answer is 0.
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains an integer
T
— the number of test cases. - For each test case:
- The first line contains an integer
N
— the number of timestamps. - The next
N
lines each contain a timestamp string in the formatYYYY-MM-DD HH:MM:SS
.
outputFormat
For each test case, output a single line containing an integer — the duration in seconds, computed as the difference between the maximum and minimum timestamps. The result should be printed to standard output (stdout).
## sample2
3
2023-04-23 10:00:00
2023-04-23 10:30:00
2023-04-23 11:00:00
5
2023-03-15 08:00:00
2023-03-15 08:15:00
2023-03-15 08:15:00
2023-03-15 09:45:00
2023-03-15 10:00:00
3600
7200
</p>