Minimum minutes needed to make the time palindromic | Function to get the required minutes ; Storing hour and minute value in letegral form ; Keep iterating till first digit hour becomes equal to second digit of minute and second digit of hour becomes equal to first digit of minute ; If mins is 60 , increase hour , and reinitilialized to 0 ; If hours is 60 , reinitialized to 0 ; Return the required time ; Given Time as a string ; Function Call
function get_palindrome_time ( str ) { let hh , mm ; hh = ( str [ 0 ] . charCodeAt ( ) - 48 ) * 10 + ( str [ 1 ] . charCodeAt ( ) - 48 ) ; mm = ( str [ 3 ] . charCodeAt ( ) - 48 ) * 10 + ( str [ 4 ] . charCodeAt ( ) - 48 ) ; let requiredTime = 0 ; while ( hh % 10 != Math . floor ( mm / 10 ) || Math . floor ( hh / 10 ) != mm % 10 ) { ++ mm ; if ( mm == 60 ) { mm = 0 ; ++ hh ; } if ( hh == 24 ) hh = 0 ; ++ requiredTime ; } return requiredTime ; } let str = " " ; document . write ( get_palindrome_time ( str . split ( ' ' ) ) ) ;