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
function cntPairsletwoArray ( arr , brr , N , M ) { let cntOddArr = 0 ; let cntOddBrr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { cntOddArr += 1 ; } } for ( let i = 0 ; i < M ; i ++ ) { if ( brr [ i ] % 2 == 1 ) { cntOddBrr += 1 ; } } return ( N * M ) - ( cntOddArr * cntOddBrr ) ; } let arr = [ 1 , 2 , 3 ] ; let N = arr . length ; let brr = [ 1 , 2 ] ; let M = brr . length ; document . write ( cntPairsletwoArray ( arr , brr , N , M ) ) ;