Binary Watch - Problem
A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.
Given an integer turnedOn which represents the number of LEDs that are currently on, return all possible times the watch could represent. You may return the answer in any order.
Format Requirements:
- The hour must not contain a leading zero. For example,
01:00is not valid. It should be1:00. - The minute must consist of two digits and may contain a leading zero. For example,
10:2is not valid. It should be10:02.
Input & Output
Example 1 — One LED On
$
Input:
turnedOn = 1
›
Output:
["1:00","2:00","4:00","8:00","0:01","0:02","0:04","0:08","0:16","0:32"]
💡 Note:
With 1 LED on, we can have hour 1,2,4,8 with minute 00 (binary: 1,10,100,1000 for hours), or hour 0 with minutes 1,2,4,8,16,32 (binary: 1,10,100,1000,10000,100000 for minutes)
Example 2 — No LEDs On
$
Input:
turnedOn = 0
›
Output:
["0:00"]
💡 Note:
With no LEDs on, only 0:00 is possible (all bits are 0)
Example 3 — Many LEDs On
$
Input:
turnedOn = 9
›
Output:
[]
💡 Note:
Maximum possible is 4+6=10 LEDs total. With hours max 11 (binary 1011 = 3 bits) and minutes max 59 (binary 111011 = 5 bits), we can't have 9 LEDs on simultaneously for any valid time
Constraints
- 0 ≤ turnedOn ≤ 10
Visualization
Tap to expand
Understanding the Visualization
1
LED Layout
4 LEDs for hours (0-11) and 6 LEDs for minutes (0-59)
2
Bit Counting
Count set bits in each valid hour and minute
3
Combination
Find pairs where total bits equals turnedOn
Key Takeaway
🎯 Key Insight: Convert the problem to counting set bits in binary representations
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code