Departure board clock
EasyOnline Assessment
Tidy up the departure times that a bus operator typed into a timetable in 12-hour format.
Each entry of times should look like h:mm AM or h:mm PM: an hour written with one or two digits and a value from 1 to 12 (a leading zero is allowed), a colon, exactly two digits for the minutes (00 to 59), one space, and AM or PM in capital letters. Entries that do not follow this are unreadable and are skipped. Remember that 12:xx AM is just after midnight (00:xx) and 12:xx PM is just after noon (12:xx).
The operator's service day runs from 04:00 to 03:59 the next morning, so a departure at 00:30 or 03:59 is the last of the day, after 23:59 and not before 04:00. Within the day, departures appear in time order.
Remove duplicates (entries that describe the same minute of the day) and write each remaining departure in 24-hour form HH:MM with two digits for both parts.
Input: times, a list of strings.
Output: a list of HH:MM strings in service-day order, or an empty list if no entry was readable.
Example 1
- Input:
- [["12:30 PM","11:50 PM","7:15 AM","12:05 AM"]]
- Output:
- ["07:15","12:30","23:50","00:05"]
- Explanation
- All four entries are readable.
12:05 AMis 00:05 and12:30 PMis 12:30. The service day starts at 04:00, so 00:05 belongs to the end of the day and goes last:07:15,12:30,23:50,00:05.
Example 2
- Input:
- [["6:00 AM","06:00 AM","13:00 PM","7:5 AM","4:00 AM"]]
- Output:
- ["04:00","06:00"]
- Explanation
6:00 AMand06:00 AMare the same departure and appear once.13:00 PM(hour out of range) and7:5 AM(minute not two digits) are skipped as unreadable.4:00 AMis exactly the start of the service day, so it sorts first.
Example 3
- Input:
- [["9:00 pm","3:60 PM","5:00PM","5 :00 PM"]]
- Output:
- []
- Explanation
- Nothing is readable (lowercase
pm, minute 60, no space), so the board is empty.
Constraints
0 <= times.length <= 500- each entry is a string of at most 12 characters, possibly not a valid time