Fill the wildcards in a time string to make the latest valid 24-hour time.
You are given a time string in 24-hour format, written as hh:mm. Some characters are replaced with ?.
Replace each ? with a digit so that the resulting string is a valid time from 00:00 to 23:59. Among all valid replacements, return the one representing the latest time in the day.
A valid time must satisfy:
00 <= hh <= 2300 <= mm <= 59If multiple valid times are possible, choose the lexicographically largest time string, which is equivalent to the latest time.
Construct the latest valid time by choosing digits for all wildcards.
time of length 5 in the form hh:mm.?.: is fixed.? characters.time.length = 5time[2] = ':'?Example 1
Input
time = "2?:?0"
Output
"23:50"
Explanation
The latest valid hour starting with 2 is 23, and the latest valid minute ending in 0 is 50.
Example 2
Input
time = "0?:3?"
Output
"09:39"
Explanation
The hour can be made as large as possible while staying valid: 09. The minute can then be maximized to 39.
Example 3
Input
time = "??:??"
Output
"23:59"
Explanation
All positions are wildcards, so the latest possible time is 23:59.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.