Binary Watch

Backtracking, problem 1 of 7

Binary Watch

Easy

LC #401

combinationsbit manipulation

Not attempted yet

A binary watch has 4 hour lights (worth 8, 4, 2, 1) and 6 minute lights (worth 32, 16, 8, 4, 2, 1). The time shown is the sum of the lit hour lights and the sum of the lit minute lights.

Given turned_on, the number of lights that are on, return every valid time the watch could be showing, in any order.

  • Hours must be 0–11, minutes 0–59.
  • Format "h:mm": no leading zero on the hour, always two digits for minutes ("1:05", not "01:5").

Example 1

Input: turned_on = 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: turned_on = 0
Output: ["0:00"]

Example 3

Input: turned_on = 9
Output: []

At most 3 hour lights (11) and 5 minute lights (59) can be on at once, so 9 is impossible.

Constraints

  • 0 ≤ turned_on ≤ 10

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.