![]() |
VOOZH | about |
Given a string S representing a time in 24 hours format, with '_' placed at positions of some digits, the task is to find the maximum time possible by replacing the characters '_' with any digit.
Examples:
Input: S = “0_:4_”
Output: 09:49
Explanation: Replacing the characters S[1] and S[4] with '9' modifies the string to "09:49", which is the maximum time possible.Input: S = “__:__”
Output: 23:59
Approach: The given problem can be solved by greedily selecting the digits for each '_' present in the string. Follow the steps below to solve the problem:
Below is the implementation of the above approach:
09:49
Time Complexity: O(1)
Auxiliary Space: O(1)
Please refer complete article on Maximize time by replacing '_' in a given 24 Hour format time for more details!