title: Maximum Product Subset Array
signature: function maximum_product_subset_array(a, n)
test_code: using Printf
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  function validate_solution(actual, expected)
      return actual == expected
  end
  
  function driver(a, n, expected)
      try
  
          if validate_solution(PLACEHOLDER_FN_NAME(a, n), expected)
              return "PASSED";
          end
          return "FAILED";
      catch exception_obj
          return string(Base.typename(typeof(exception_obj)).wrapper);
      end
  end
  
  function main()
      
      result = driver([22, 62, 97], 2, 1364);
      @printf("TEST-0...%s\n",result);
      
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 43, 1);
      @printf("TEST-1...%s\n",result);
      
      result = driver([-92, -78, -74, -72, -70, -66, -46, -44, -42, -34, -32, -30, -10, 18, 30, 34, 56, 64, 66], 10, 510537135542353920);
      @printf("TEST-2...%s\n",result);
      
      result = driver([0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], 16, 1);
      @printf("TEST-3...%s\n",result);
      
      result = driver([1, 2, 3, 18, 20, 33, 38, 53, 55, 56, 67, 80, 83, 87, 90, 97, 98], 9, 7895685600);
      @printf("TEST-4...%s\n",result);
      
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11, 1);
      @printf("TEST-5...%s\n",result);
      
  end
  
  main()
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;
  }