Latest Time by Replacing Hidden Digits

You are given a string time in the form of hh:mm, where some of the digits in the string are hidden and represented by ?.

The valid times are those inclusively between 00:00 and 23:59.

Return the latest valid time you can get from time by replacing the hidden digits.

Example 1
Inputtime = "2?:?0"
Output"23:50"
The latest hour beginning with the digit '2' is 23 and the latest minute ending with the digit '0' is 50.
Example 2
Inputtime = "0?:3?"
Output"09:39"
Replacing the hidden digits with 9 gives the latest valid hour starting with 0 and the latest valid minute ending with 3.

Constraints

  • time is in the format hh:mm.
  • It is guaranteed that you can produce a valid time from the given string.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate