1768. Mirror Clock Times

Easy1.5 points estimatedEnumerationString

A hotel lobby has a digital wall clock that shows the time as four digits, HH:MM. Guests call a time mirror-lucky when its four digits read the same forwards and backwards once the colon is ignored, such as 12:21 or 05:50. You are given start and end, two valid 24-hour clock strings in HH:MM form (00:00 to 23:59) with start <= end.

Return every mirror-lucky time from start to end, both ends inclusive, as HH:MM strings in ascending chronological order. If there is none, return an empty list. Walk through the minutes of the day between the two times and test each one; a day has only 1440 minutes, so this is O(1) time and O(1) extra space apart from the answer. At most 16 times can ever be returned.

Example 1

Input:
start = "00:00", end = "23:59"
Output:
["00:00","01:10","02:20","03:30","04:40","05:50","10:01","11:11","12:21","13:31","14:41","15:51","20:02","21:12","22:22","23:32"]
Explanation:

All 16 mirror-lucky times of the day are listed in order.

Example 2

Input:
start = "12:00", end = "12:30"
Output:
["12:21"]
Explanation:

Only 12:21 reads the same in both directions in this window.

Example 3

Input:
start = "09:00", end = "10:30"
Output:
["10:01"]
Explanation:

09:90 does not exist, so the first match is 10:01.

Constraints

start and end are valid "HH:MM" strings, 00:00 ≤ start ≤ end ≤ 23:59; at most 16 results.

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 4,000 msC++ 1,000 msJava 2,000 msJavaScript 2,000 msTypeScript 2,000 ms

Expected complexity

Time
O(1)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…