Ctrl K

A Clock With Blank Digits

Easy
A digital clock shows the time as "hh:mm", from "00:00" to "23:59". Some of its segments have gone dark, so some digits in the string display are replaced by ?. In how many ways can each ? be replaced by a digit from 0 to 9 so that the result is a real time of day?
Example 1
display="2?:4?" → 40

The hours can be 20 to 23 (4 options) and the minutes 40 to 49 (10 options): 4 · 10 = 40 in total.

Example 2
display="?9:?5" → 12

The hours are 09 or 19 (there is no 29) and the minutes 05, 15, …, 55. The answer is 2 · 6 = 12.

Example 3
display="13:07" → 1
Constraints
  • len(display) == 5, display[2] == ':'
  • The other characters are digits or ?
  • At least one replacement gives a valid time
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNearest Short Hex Color EasyStrike Out a Digit for the Maximum EasyHighest Letter in Both Cases EasyLatest Time on a Broken Display EasyNext Time From the Same Digits Medium
loading Python…
Input
display="2?:4?"
Expected
40

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.