1774. Lit Watch Times
A quirky binary watch shows the hour (0 to 11) on 4 LEDs and the minute (0 to 59) on 6 LEDs. Each LED stands for one bit of the number, and an LED is on exactly when its bit is 1. Given the integer lit, the total number of LEDs currently switched on across both groups, return every time the watch could be showing.
Format each time as "H:MM": the hour without a leading zero and the minute always with two digits, for example "3:07" or "11:45". Sort the answer by hour first and then by minute, and return an empty list when no time matches. Enumerate all 12 * 60 = 720 hour and minute pairs and keep those whose combined popcount equals lit. This takes O(720) = O(1) time and O(1) extra space besides the output, and there are at most 190 matching times.
Example 1
- Input:
- lit = 0
- Output:
- ["0:00"]
- Explanation:
Only midnight-style 0:00 has every LED off.
Example 2
- Input:
- lit = 1
- Output:
- ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]
- Explanation:
One LED on means either an hour of 1, 2, 4 or 8 at minute 0, or hour 0 with a minute of 1, 2, 4, 8, 16 or 32.
Constraints
0 ≤ lit ≤ 10 (at most 190 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)