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 ; Driver code ; Input String ; Function call
def minOperations ( N ) : NEW_LINE INDENT even = 0 ; NEW_LINE odd = 0 ; NEW_LINE for it in N : NEW_LINE INDENT if ( int ( ord ( it ) - ord ( '0' ) ) % 2 == 0 ) : NEW_LINE INDENT even += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT odd += 1 ; NEW_LINE DEDENT DEDENT if ( odd == 0 or odd == 1 ) : NEW_LINE INDENT print ( " Not ▁ Possible " + " " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 ; NEW_LINE for it in N : NEW_LINE INDENT if ( int ( ord ( it ) - ord ( '0' ) ) % 2 == 0 ) : NEW_LINE INDENT ans += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT ans = 0 ; NEW_LINE DEDENT DEDENT if ( odd % 2 != 0 ) : NEW_LINE INDENT ans += 1 ; NEW_LINE DEDENT print ( ans , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = "12345" ; NEW_LINE minOperations ( N ) ; NEW_LINE DEDENT