Problem
Ask
Submissions

Problem: Binary Watch

Medium
30 min
Explore how to use backtracking to solve the binary watch problem where LEDs display hours and minutes. Learn to generate all valid times with enabled LEDs and handle constraints like leading zeros effectively.

Statement

A binary watch has 4 LEDs for displaying hours (ranging from 0 to 11) and 6 for displaying minutes (ranging from 0 to 59). Each LED can be on (1) or off (0), with the least significant bit on the right. For example, the binary watch below reads “9:22.”

Given an integer enabled, which represents the number of LEDs currently turned on, return all possible times that the watch could display. You may return the answer in any order.

Note: Remember the following regarding leading zeros:

  • The hour cannot have a leading zero (e.g., “01:00” is invalid, it should be “1:00”).

  • The minute must be two digits and may include a leading zero (e.g., “10:2” is invalid, it should be “10:02”).

Constraints:

  • 00 \leq enabled 10\leq 10

Problem
Ask
Submissions

Problem: Binary Watch

Medium
30 min
Explore how to use backtracking to solve the binary watch problem where LEDs display hours and minutes. Learn to generate all valid times with enabled LEDs and handle constraints like leading zeros effectively.

Statement

A binary watch has 4 LEDs for displaying hours (ranging from 0 to 11) and 6 for displaying minutes (ranging from 0 to 59). Each LED can be on (1) or off (0), with the least significant bit on the right. For example, the binary watch below reads “9:22.”

Given an integer enabled, which represents the number of LEDs currently turned on, return all possible times that the watch could display. You may return the answer in any order.

Note: Remember the following regarding leading zeros:

  • The hour cannot have a leading zero (e.g., “01:00” is invalid, it should be “1:00”).

  • The minute must be two digits and may include a leading zero (e.g., “10:2” is invalid, it should be “10:02”).

Constraints:

  • 00 \leq enabled 10\leq 10