Minimum possible number with the given operation | Function to return the minimum possible integer that can be obtained from the given integer after performing the given operations ; For every digit ; Digits less than 5 need not to be changed as changing them will lead to a larger number ; The resulting integer cannot have leading zero ; Driver code
function minInt ( str ) { for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] . charCodeAt ( ) >= ( ' ' ) . charCodeAt ( ) ) { str [ i ] = String . fromCharCode ( ( ( ' ' ) . charCodeAt ( ) - ( str [ i ] ) . charCodeAt ( ) ) + ( ' ' ) . charCodeAt ( ) ) ; } } if ( str [ 0 ] == ' ' ) str [ 0 ] = ' ' ; let s = str . join ( " " ) ; return s ; } let str = " " ; document . write ( minInt ( str . split ( ' ' ) ) ) ;