#C7096. Most Sighted Animal in a Time Period
Most Sighted Animal in a Time Period
Most Sighted Animal in a Time Period
You are given a series of animal sighting logs. Each log contains a timestamp, a unique animal ID, and a location. Given a specific time window defined by a start time and an end time (both inclusive), your task is to determine which animal was sighted the most number of times within this period. In the case of a tie, the animal ID that is lexicographically smallest (i.e., appears first in alphabetical order) should be returned.
Note: All timestamps follow the format \(YYYY\text{-}MM\text{-}DD\ HH:MM:SS\).
inputFormat
The input is read from stdin and is structured as follows:
- An integer \(n\) representing the number of sighting logs.
- Then \(n\) lines follow, each containing a log entry in the format:
timestamp;animal_id;location
, wheretimestamp
is in the format \(YYYY-MM-DD HH:MM:SS\). - The next line is a string representing the start time in the same timestamp format.
- The last line is a string representing the end time in the same timestamp format.
outputFormat
Output to stdout a single line containing the unique ID of the most sighted animal in the given period. If there is a tie, output the lexicographically smallest animal ID.
## sample1
2023-01-01 12:00:00;ELEPHANT;Zone A
2023-01-01 00:00:00
2023-01-01 23:59:59
ELEPHANT