Binary Watch

Easy

A binary watch shows the time with 10 LEDs. The top 4 LEDs show the hour (0 to 11) and the bottom 6 show the minute (0 to 59). Each LED is worth a power of two: the hour LEDs are worth 8, 4, 2 and 1, and the minute LEDs are worth 32, 16, 8, 4, 2 and 1. The hour is the sum of the lit hour LEDs, and the minute is the sum of the lit minute LEDs.

Given an integer turnedOn, the number of LEDs that are lit, return every time the watch could be showing. You can return them in any order.

Write each time as "h:mm":

  • The hour has no leading zero: "1:00" is right, "01:00" is not.
  • The minute always has two digits: "10:02" is right, "10:2" is not.

Some sets of lit LEDs add up to an hour above 11 or a minute above 59. Those aren't real times, so leave them out.

Examples

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 1: one lit LEDhourminute8421321684214:00hour 4minute 0Each of the 10 LEDs gives one time when it's the only one lit.

The one lit LED is either one of the 4 hour LEDs (and the minute is 0) or one of the 6 minute LEDs (and the hour is 0). That gives 10 times.

Example 2

Input:  turnedOn = 9
Output: []

A real hour uses at most 3 LEDs (7 is 0111 and 11 is 1011), and a real minute uses at most 5 (59 is 111011). That's 8 LEDs at most, so 9 lit LEDs can't show a real time.

Example 3

Input:  turnedOn = 0
Output: ["0:00"]

With every LED off, the hour and the minute are both 0.

Example 4

Input:  turnedOn = 8
Output: ["7:31","7:47","7:55","7:59","11:31","11:47","11:55","11:59"]
Example 4: 8 lit LEDshourminute84213216842111:598 + 2 + 132+16+8+2+13 hour LEDs and 5 minute LEDs: the most a real time can use.

Only 7 and 11 light 3 hour LEDs, and only 31, 47, 55 and 59 light 5 minute LEDs. Every pair of one of each works, so there are 2 × 4 = 8 times.

Constraints

  • 0 <= turnedOn <= 10
TypeScript
Loading editor…
Test cases11
Case 1
turnedOn = 1
Case 2
turnedOn = 9
Case 3
turnedOn = 0
Case 4
turnedOn = 8
Case 5
turnedOn = 2
Case 6
turnedOn = 3
Case 7
turnedOn = 4
Case 8
turnedOn = 5
Case 9
turnedOn = 6
Case 10
turnedOn = 7
Case 11
turnedOn = 10