Minimum product pair an array of positive Integers | Function to calculate minimum product of pair ; Initialize first and second minimums . It is assumed that the array has at least two elements . ; Traverse remaining array and keep track of two minimum elements ( Note that the two minimum elements may be same if minimum element appears more than once ) more than once ) ; Driver program to test above function
function printMinimumProduct ( arr , n ) { let first_min = Math . min ( arr [ 0 ] , arr [ 1 ] ) ; let second_min = Math . max ( arr [ 0 ] , arr [ 1 ] ) ; for ( let i = 2 ; i < n ; i ++ ) { if ( arr [ i ] < first_min ) { second_min = first_min ; first_min = arr [ i ] ; } else if ( arr [ i ] < second_min ) second_min = arr [ i ] ; } return first_min * second_min ; } let a = [ 11 , 8 , 5 , 7 , 5 , 100 ] ; let n = a . length ; document . write ( printMinimumProduct ( a , n ) ) ;