Count pairs with Even Product from two given arrays | Function to count pairs ( arr [ i ] , brr [ j ] ) whose product is an even number ; Stores count of odd numbers in arr [ ] ; Stores count of odd numbers in brr [ ] ; Traverse the array , arr [ ] ; If arr [ i ] is an odd number ; Update cntOddArr ; Traverse the array , brr [ ] ; If brr [ i ] is an odd number ; Update cntOddArr ; Return pairs whose product is an even number ; Driver Code
def cntPairsInTwoArray ( arr , brr , N , M ) : NEW_LINE INDENT cntOddArr = 0 NEW_LINE cntOddBrr = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] & 1 ) : NEW_LINE INDENT cntOddArr += 1 NEW_LINE DEDENT DEDENT for i in range ( M ) : NEW_LINE INDENT if ( brr [ i ] & 1 ) : NEW_LINE INDENT cntOddBrr += 1 NEW_LINE DEDENT DEDENT return ( N * M ) - ( cntOddArr * cntOddBrr ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE brr = [ 1 , 2 ] NEW_LINE M = len ( brr ) NEW_LINE print ( cntPairsInTwoArray ( arr , brr , N , M ) ) NEW_LINE DEDENT