#K71042. Department with Most Unique Visitors
Department with Most Unique Visitors
Department with Most Unique Visitors
In this problem, you are given a set of logs for one or more days. Each log entry indicates a client visiting a department at a given timestamp. Your task is to determine, for each day, the department that had the highest number of unique visitors. In the event multiple departments have the same number of unique visitors, choose the department with the smallest numerical identifier.
The log entries are given in the format: ( client_id, department_id, timestamp )
For example, given the log entry "101, 1, 2023-03-25 10:15:23", client 101 visited department 1 at the specified timestamp. The input comprises multiple datasets (days) and ends when a day identifier of 0 is encountered.
Your solution must read from standard input (stdin) and write the results for each day to standard output (stdout), with each result on a separate line.
inputFormat
Input is provided via stdin. The first line of each dataset contains an integer representing the day (this value is not used in calculations but indicates the start of a dataset). The second line contains an integer ( n ) representing the number of log entries for that day. The next ( n ) lines each contain a log in the format "client_id, department_id, timestamp". The input terminates when a day value of 0 is encountered.
outputFormat
For each dataset (day) provided in the input, output the department id that has the highest number of unique visitors. If there is a tie, output the smallest department id. Each output should be printed on a separate line.## sample
1
6
101, 1, 2023-03-25 10:15:23
102, 1, 2023-03-25 11:20:45
101, 2, 2023-03-25 10:30:00
103, 1, 2023-03-25 12:00:00
104, 2, 2023-03-25 12:30:00
105, 2, 2023-03-25 13:00:00
0
1