Ctrl K

Time Behind the Smudges

Easy
A digital clock shows the time as hh:mm, anywhere from 00:00 to 23:59, but the screen is smudged and some digits cannot be read: in the string display they are replaced by ?. Return the latest time that could be hiding behind this reading, in the same hh:mm format.
Example 1
display="?5:4?" → '15:49'

The hour ends in 5, so it cannot start with 2 (there is no 25 o'clock), and we take 15. Minutes 4? give at most 49.

Example 2
display="2?:??" → '23:59'

The hour starts with 2, so its second digit is at most 3. That gives 23:59.

Example 3
display="07:?1" → '07:51'
Constraints
  • display has the form hh:mm, where each of the four positions is a digit or ?
  • At least one valid time matches the reading
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPalindrome From Letter Tiles EasyPalindrome With One Eraser Stroke EasyRise and Fall Lineup EasyMost Even L/R Pieces EasyThe Biggest Odd Chunk Easy
loading Python…
Input
display="?5:4?"
Expected
'15:49'

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