Product of maximum in first array and minimum in second | Function to calculate the product ; Initialize max of first array ; Initialize min of second array ; To find the maximum element in first array ; To find the minimum element in second array ; Process remaining elements ; Driver Code
function minMaxProduct ( arr1 , arr2 , n1 , n2 ) { let max = arr1 [ 0 ] ; let min = arr2 [ 0 ] ; let i ; for ( i = 1 ; i < n1 && i < n2 ; ++ i ) { if ( arr1 [ i ] > max ) max = arr1 [ i ] ; if ( arr2 [ i ] < min ) min = arr2 [ i ] ; } while ( i < n1 ) { if ( arr1 [ i ] > max ) max = arr1 [ i ] ; i ++ ; } while ( i < n2 ) { if ( arr2 [ i ] < min ) min = arr2 [ i ] ; i ++ ; } return max * min ; } let arr1 = [ 10 , 2 , 3 , 6 , 4 , 1 ] ; let arr2 = [ 5 , 1 , 4 , 2 , 6 , 9 ] ; let n1 = 6 ; let n2 = 6 ; document . write ( minMaxProduct ( arr1 , arr2 , n1 , n2 ) ) ;