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
function getTime ( s , n ) { let res = " " ; let h = parseInt ( s . substring ( 0 , 0 + 2 ) ) ; let m = parseInt ( s . substring ( 3 , 3 + 2 ) ) ; let rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; let rev_hs = ( rev_h ) . toString ( ) ; if ( h == 23 && m >= 32 ) { res = " " ; } else if ( m < rev_h ) { let temp = " " ; if ( h < 10 ) temp = " " ; temp = temp + h . toString ( ) ; if ( rev_h < 10 ) res = res + temp + " " + rev_hs ; else res = res + temp + " " + rev_hs ; } else { h ++ ; rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; rev_hs = ( rev_h ) . toString ( ) ; let temp = " " ; if ( h < 10 ) temp = " " ; temp = temp + h . toString ( ) ; if ( rev_h < 10 ) res = res + temp + " " + rev_hs ; else res = res + temp + " " + rev_hs ; } return res ; } let s = " " ; let n = s . length ; document . write ( getTime ( s , n ) ) ;