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:00 is not valid. It should be 1:00.
  • The minute must consist of two digits and may contain a leading zero. For example, 10:2 is not valid. It should be 10: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
Binary Watch: LED to Time ConversionHour LEDs (4 bits)8421Minute LEDs (6 bits)32168421Time: 8:29 (1 hour bit + 4 minute bits = 5 total LEDs)Hour: 8 = 1000₂ (1 bit) | Minute: 29 = 011101₂ (4 bits)For turnedOn = 5, this would be a valid resultAlgorithm: Check all hour-minute combinations for matching bit count
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
Asked in
Google 25 Amazon 20 Apple 15 Microsoft 12
28.5K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen