#C7554. Longest Call Duration Per Day
Longest Call Duration Per Day
Longest Call Duration Per Day
A telecommunications company is interested in analyzing call durations made by its customers over several days. For each day, the company wants to identify the customer who accumulated the longest total call duration. If multiple customers have the same total call duration for a day, then the customer whose name comes first lexicographically should be chosen.
Each call record consists of a date, a start time, an end time, and the customer's name. The call times are provided in 24-hour format.
Assume the call durations are computed in minutes. Your task is to implement a solution that reads the call records from standard input, processes them, and prints the result for each day to standard output. The result for each day should list the date and the winning customer separated by a space.
Note: If multiple call records exist for a day, sum the call durations for each customer and then determine which customer had the highest total duration. In the case of a tie, choose the lexicographically smallest customer name.
inputFormat
The input is read from standard input and is formatted as follows:
N record_1 record_2 ... record_N
Here, N is an integer denoting the number of call records. Each record is a single line containing four space-separated values:
date
in the formatYYYY-MM-DD
,start_time
in the formatHH:MM
,end_time
in the formatHH:MM
, andcustomer_name
(a string without spaces).
outputFormat
The output should be printed to standard output. For each unique date present in the input, output a line in the following format:
YYYY-MM-DD customer_name
The dates should be printed in ascending order. For each date, customer_name
is the one with the longest total call duration (or the lexicographically smallest one in the event of a tie).
5
2023-10-01 08:00 09:30 alice
2023-10-01 10:00 11:00 bob
2023-10-01 09:45 10:30 alice
2023-10-02 08:00 09:00 charlie
2023-10-02 09:00 10:00 alice
2023-10-01 alice
2023-10-02 alice
</p>