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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Backtracking
Bit counting
Combinations
Formatting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: integer turned_on from 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...


Submit Your Answer
Markdown supported