Find the time which is palindromic and comes after the given time | Function to return the required time ; To store the resultant time ; Hours are stored in h as integer ; Minutes are stored in m as integer ; Reverse of h ; Reverse of h as a string ; If MM < reverse of ( HH ) ; 0 is added if HH < 10 ; 0 is added if rev_h < 10 ; Increment hours ; Reverse of the hour after incrementing 1 ; 0 is added if HH < 10 ; 0 is added if rev_h < 10 ; Driver code
def getTime ( s , n ) : NEW_LINE INDENT res = " " NEW_LINE h = int ( s [ 0 : 2 ] ) ; NEW_LINE m = int ( s [ 3 : 5 ] ) ; NEW_LINE rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) // 10 ; NEW_LINE rev_hs = str ( rev_h ) NEW_LINE temp = " " NEW_LINE if ( h == 23 and m >= 32 ) : NEW_LINE INDENT res = " - 1" ; NEW_LINE DEDENT elif ( m < rev_h ) : NEW_LINE INDENT if ( h < 10 ) : NEW_LINE INDENT temp = "0" ; NEW_LINE DEDENT temp = temp + str ( h ) ; NEW_LINE if ( rev_h < 10 ) : NEW_LINE INDENT res = res + temp + " : 0" + rev_hs ; NEW_LINE DEDENT else : NEW_LINE INDENT res = res + temp + " : " + rev_hs ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT h += 1 NEW_LINE rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) // 10 ; NEW_LINE rev_hs = str ( rev_h ) ; NEW_LINE if ( h < 10 ) : NEW_LINE INDENT temp = "0" ; NEW_LINE DEDENT temp = temp + str ( h ) ; NEW_LINE if ( rev_h < 10 ) : NEW_LINE INDENT res = res + temp + " : 0" + rev_hs ; NEW_LINE DEDENT else : NEW_LINE INDENT res = res + temp + " : " + rev_hs ; NEW_LINE DEDENT DEDENT return res ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "21:12" ; NEW_LINE n = len ( s ) ; NEW_LINE print ( getTime ( s , n ) ) ; NEW_LINE DEDENT