title: Minimum Product Subset Array
signature: minimum_product_subset_array <- function(a, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(3L, 6L, 7L, 8L, 8L, 9L, 12L, 12L, 12L, 13L, 15L, 15L, 15L, 16L, 18L, 18L, 18L, 19L, 20L, 21L, 22L, 22L, 23L, 28L, 29L, 30L, 30L, 33L, 33L, 35L, 35L, 36L, 40L, 43L, 58L, 63L, 73L, 78L, 82L, 83L, 84L, 87L, 89L, 89L, 92L, 94L), 23L, 
          3L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(18L, -6L, -8L, 98L, 66L, -86L, 24L, 6L, 58L, 74L, 82L), 10L, 
          -297032800813056L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 25L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(97L, 79L, 93L, 41L, 76L, 34L, 94L, 57L, 63L, 98L, 52L, 62L, 96L, 7L, 63L, 44L, 55L, 43L, 36L, 66L, 35L, 14L, 24L, 40L, 26L, 16L, 67L, 19L, 31L, 86L, 64L, 93L, 85L, 86L, 66L, 24L, 73L, 86L, 45L, 99L, 25L, 98L, 38L, 57L), 30L, 
          7L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-58L, -48L, -46L, -36L, 0L, 18L), 3L, 
          -128064L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L), 36L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(1L, 3L, 5L, 15L, 18L, 19L, 21L, 23L, 29L, 29L, 33L, 33L, 34L, 37L, 39L, 43L, 43L, 68L, 73L, 74L, 75L, 84L, 87L, 88L, 89L, 90L, 93L), 18L, 
          1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 20L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(74L, 74L, 8L, 74L, 85L, 41L, 31L, 3L, 84L, 46L, 73L, 39L, 64L, 72L, 28L, 83L, 98L, 27L, 64L, 7L, 95L, 37L, 10L, 38L, 77L, 32L, 69L, 72L, 62L, 96L, 5L, 81L, 34L, 96L, 80L, 25L, 38L), 33L, 
          3L
      )))
  
  }
  
  main()
source_py: def minimum_product_subset_array(a, n):
      if (n == 1):
          return a[0]
      max_neg = float('-inf')
      min_pos = float('inf')
      count_neg = 0
      count_zero = 0
      prod = 1
      for i in range(0, n):
          if (a[i] == 0):
              count_zero = (count_zero + 1)
              continue
          if (a[i] < 0):
              count_neg = (count_neg + 1)
              max_neg = max(max_neg, a[i])
          if (a[i] > 0):
              min_pos = min(min_pos, a[i])
          prod = (prod * a[i])
      if ((count_zero == n) or ((count_neg == 0) and (count_zero > 0))):
          return 0
      if (count_neg == 0):
          return min_pos
      if (((count_neg & 1) == 0) and (count_neg != 0)):
          prod = int((prod / max_neg))
      return prod
source_cpp: int minimum_product_subset_array(vector<int> a, int n) {
    if ( n == 1 ) return a [ 0 ];
    int max_neg = INT_MIN;
    int min_pos = INT_MAX;
    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 ] );
      }
      if ( a [ i ] > 0 ) min_pos = min ( min_pos, a [ i ] );
      prod = prod * a [ i ];
    }
    if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0;
    if ( count_neg == 0 ) return min_pos;
    if ( ! ( count_neg & 1 ) && count_neg != 0 ) {
      prod = prod / max_neg;
    }
    return prod;
  }