Minimum deletions to convert given integer to an odd number whose sum of digits is even | Set 2 | Function to find minimum count of digits required to be remove to make N odd and the sum of digits of N even ; Stores count of even digits ; Stores count of odd digits ; Iterate over the digits of N ; If current digit is even ; Update even ; Otherwise ; Update odd ; Base conditions ; Stores count of digits required to be removed to make N odd and the sum of digits of N even ; Iterate over the digits of N ; If current digit is even ; Update ans ; Otherwise , ; Update ans ; If count of odd digits is odd ; Update ans ; Finally print the ans ; Input string ; Function call
function minOperations ( N ) { var even = 0 ; var odd = 0 ; for ( var it = 0 ; it < N . length ; it ++ ) { if ( ( N [ it ] - ' ' ) % 2 == 0 ) { even ++ ; } else { odd ++ ; } } if ( odd == 0 odd == 1 ) { document . write ( " " + " " ) ; } else { var ans = 0 ; for ( var it = 0 ; it < N . length ; it ++ ) { if ( ( N [ it ] - ' ' ) % 2 == 0 ) { ans ++ ; } else { ans = 0 ; } } if ( odd % 2 ) { ans ++ ; } document . write ( ans ) ; } } var N = " " ; minOperations ( N ) ;