Read Every Possible Time on a Binary LED Watch
Last updated: November 29, 2026
Quick Overview
A binary watch shows hours (0 to 11) with 4 LEDs and minutes (0 to 59) with 6 LEDs. Given how many LEDs are on, return every time the watch could be showing, formatted as h:mm.
0
0
0 solved
A binary watch shows hours (0 to 11) with 4 LEDs and minutes (0 to 59) with 6 LEDs. Given how many LEDs are on, return every time the watch could be showing, formatted as h:mm.
A quick Google phone screen warm-up. The interviewer checks that you can either enumerate LED subsets with backtracking and filter invalid values, or flip the problem around and loop over all 720 valid times counting bits.
What the Interviewer Expects
- Chooses exactly n LEDs out of 10 via combinations
- Filters out hours above 11 and minutes above 59
- Formats minutes with two digits and hours without a leading zero
- Mentions the simpler 12 x 60 loop with popcount
- Handles n above 8 (no valid time)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Which approach would you ship and why?
- How would you extend it to a 24-hour watch with 5 hour LEDs?
- How many times are possible for each n from 0 to 10?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: integer
turned_onfrom 0 to 10. - Output: all valid times
"h:mm"with that many LEDs lit, sorted. - Hours have no leading zero (
"1:05"), minutes always two digits. - Example: 1 LED give...
High-Level Design
Backtracking version: treat the 10 LEDs as weights [8, 4, 2, 1] for hours and [32, 16, 8, 4, 2, 1] for minutes. Choose turned_on of them in increasing index order (combinations), accumulating ho...