title: Maximum Product Subset Array
signature: def maximum_product_subset_array(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;
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(a, n, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              a, n),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([22, 62, 97], 2, 1364)
      print(f"TEST-0...{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)
      print(f"TEST-1...{result}")
  
      result = driver([-92, -78, -74, -72, -70, -66, -46, -44, -42, -34, -32, -30, -10, 18, 30, 34, 56, 64, 66], 10, 510537135542353920)
      print(f"TEST-2...{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)
      print(f"TEST-3...{result}")
  
      result = driver([1, 2, 3, 18, 20, 33, 38, 53, 55, 56, 67, 80, 83, 87, 90, 97, 98], 9, 7895685600)
      print(f"TEST-4...{result}")
  
      result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11, 1)
      print(f"TEST-5...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5']
question_info.entry_fn_name: maximum_product_subset_array
question_info.test_list: [{"idx": 0, "outputs": 1364, "inputs": {"a": [22, 62, 97], "n": 2}}, {"idx": 1, "outputs": 1, "inputs": {"a": [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], "n": 43}}, {"idx": 2, "outputs": 510537135542353920, "inputs": {"a": [-92, -78, -74, -72, -70, -66, -46, -44, -42, -34, -32, -30, -10, 18, 30, 34, 56, 64, 66], "n": 10}}, {"idx": 3, "outputs": 1, "inputs": {"a": [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], "n": 16}}, {"idx": 4, "outputs": 7895685600, "inputs": {"a": [1, 2, 3, 18, 20, 33, 38, 53, 55, 56, 67, 80, 83, 87, 90, 97, 98], "n": 9}}, {"idx": 5, "outputs": 1, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 11}}]
question_info.entry_cls_name: Solution