title: Maximum Product Subset Array
signature: function maximumProductSubsetArray($a, $n) {
source_py: def maximum_product_subset_array(a, n):
      if (n == 1):
          return a[0]
      max_neg = (- 999999999999)
      count_neg = 0
      count_zero = 0
      prod = 1
      for i in range(n):
          if (a[i] == 0):
              count_zero += 1
              continue
          if (a[i] < 0):
              count_neg += 1
              max_neg = max(max_neg, a[i])
          prod = (prod * a[i])
      if (count_zero == n):
          return 0
      if (count_neg & 1):
          if ((count_neg == 1) and (count_zero > 0) and ((count_zero + count_neg) == n)):
              return 0
          prod = int((prod / max_neg))
      return prod
source_cpp: int maximum_product_subset_array(vector<int> a, int n) {
    if ( n == 1 ) return a [ 0 ];
    int max_neg = INT_MIN;
    int count_neg = 0, count_zero = 0;
    int prod = 1;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( a [ i ] == 0 ) {
        count_zero ++;
        continue;
      }
      if ( a [ i ] < 0 ) {
        count_neg ++;
        max_neg = max ( max_neg, a [ i ] );
      }
      prod = prod * a [ i ];
    }
    if ( count_zero == n ) return 0;
    if ( count_neg & 1 ) {
      if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0;
      prod = prod / max_neg;
    }
    return prod;
  }