Maximize time by replacing ' _ ' in a given 24 Hour format time | Function to find the maximum time possible by replacing each ' _ ' with any digit ; If the first character is '_ ; If s [ 1 ] is ' _ ' or s [ 1 ] is less than 4 ; Update s [ 0 ] as 2 ; Otherwise , update s [ 0 ] = 1 ; If s [ 1 ] is equal to '_ ; If s [ 0 ] is equal to '2 ; Otherwise ; If S [ 3 ] is equal to '_ ; If s [ 4 ] is equal to '_ ; Return the modified string ; Driver Code
def maximumTime ( s ) : NEW_LINE INDENT s = list ( s ) NEW_LINE DEDENT ' NEW_LINE INDENT if ( s [ 0 ] == ' _ ' ) : NEW_LINE INDENT if ( ( s [ 1 ] == ' _ ' ) or ( s [ 1 ] >= '0' and s [ 1 ] < '4' ) ) : NEW_LINE INDENT s [ 0 ] = '2' NEW_LINE DEDENT else : NEW_LINE INDENT s [ 0 ] = '1' NEW_LINE DEDENT DEDENT DEDENT ' NEW_LINE INDENT if ( s [ 1 ] == ' _ ' ) : NEW_LINE DEDENT ' NEW_LINE INDENT if ( s [ 0 ] == '2' ) : NEW_LINE INDENT s [ 1 ] = '3' NEW_LINE DEDENT else : NEW_LINE INDENT s [ 1 ] = '9' NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT if ( s [ 3 ] == ' _ ' ) : NEW_LINE INDENT s [ 3 ] = '5' NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT if ( s [ 4 ] == ' _ ' ) : NEW_LINE INDENT s [ 4 ] = '9' NEW_LINE DEDENT s = ' ' . join ( s ) NEW_LINE return s NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = "0 _ : 4 _ " NEW_LINE print ( maximumTime ( S ) ) NEW_LINE DEDENT