Maximize count of strings of length 3 that can be formed from N 1 s and M 0 s | Function that counts the number of strings of length three that can be made with given m 0 s and n 1 s ; Iterate until N & M are positive ; Case 1 : ; Case 2 : ; Print the count of strings ; Driver code ; Given count of 1 s and 0 s ; Function call
def number_of_strings ( N , M ) : NEW_LINE INDENT ans = 0 NEW_LINE while ( N > 0 and M > 0 ) : NEW_LINE INDENT if ( N > M ) : NEW_LINE INDENT if ( N >= 2 ) : NEW_LINE INDENT N -= 2 NEW_LINE M -= 1 NEW_LINE ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if M >= 2 : NEW_LINE INDENT M -= 2 NEW_LINE N -= 1 NEW_LINE ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 4 NEW_LINE M = 19 NEW_LINE number_of_strings ( N , M ) NEW_LINE DEDENT