If current element is zero , maximum product cannot end at current element . Update minval with 1 and maxval with 0. maxval is updated to 0 as in case all other elements are negative , then maxval is 0.
else if ( arr [ i ] == 0 ) { minval = 1 ; maxval = 0 ; }