#K36657. Ticket Purchase Timeline
Ticket Purchase Timeline
Ticket Purchase Timeline
You are given a list of ticket purchase records. Each record consists of a person's name and the time at which a ticket was purchased in the \(HH:MM\)
format. Your task is to determine who bought the ticket first (i.e. at the earliest time) and who bought the ticket last (i.e. at the latest time).
Note: The time is given in a 24-hour clock format, so a time like 09:30
comes before 10:15
. In the event that there is only one ticket purchase, that person is both the first and the last purchaser.
Example:
Input: 4 Alice 09:30 Bob 10:15 Alice 11:00 Charlie 08:45</p>Output: Charlie Alice
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer
n
denoting the number of tickets purchased. - Each of the following
n
lines contains a person's name and a time in\(HH:MM\)
format, separated by a space.
outputFormat
Print to stdout two space-separated names on a single line:
- The name of the person who bought the ticket first (i.e., the earliest time).
- The name of the person who bought the ticket last (i.e., the latest time).
4
Alice 09:30
Bob 10:15
Alice 11:00
Charlie 08:45
Charlie Alice
</p>