Reduce the number to minimum multiple of 4 after removing the digits | javascript implementation of the approach ; Function to return the minimum number that can be formed after removing the digits which is a multiple of 4 ; For every digit of the number ; Check if the current digit is divisible by 4 ; If any subsequence of two digits is divisible by 4 ; Driver code
var TEN = 10 ; function minNum ( str , len ) { var res = Number . MAX_VALUE ; for ( var i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' str [ i ] == ' ' ) { res = Math . min ( res , str [ i ] - ' ' ) ; } } for ( i = 0 ; i < len - 1 ; i ++ ) { for ( j = i + 1 ; j < len ; j ++ ) { var num = ( str [ i ] - ' ' ) * TEN + ( str [ j ] - ' ' ) ; if ( num % 4 == 0 ) { res = Math . min ( res , num ) ; } } } return ( ( res == Number . MAX_VALUE ) ? - 1 : res ) ; } var str = " " ; var len = str . length ; document . write ( minNum ( str , len ) ) ;