Easy

Quiz

#401 Binary Watch

APPROACH

A binary watch has 4 LEDs encoding hours (0–11) and 6 LEDs encoding minutes (0–59) in binary, with the least significant bit on the right.

Given turnedOn (the number of LEDs currently illuminated), enumerate every valid time the watch could be displaying. Return the results in any order.

Formatting: hours omit leading zeros ("1:00" not "01:00"); minutes always use exactly two digits ("10:02" not "10:2").

Example 1:

Input: turnedOn = 1
Output: ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]

Example 2:

Input: turnedOn = 9
Output: []
1 of 4
1:00

What is the optimal approach for this problem?