title: Maximum Possible Difference Two Subsets Array
signature: function maximum_possible_difference_two_subsets_array(arr, n)
source_py: def maximum_possible_difference_two_subsets_array(arr, n):
      SubsetSum_1 = 0
      SubsetSum_2 = 0
      for i in range(0, n):
          isSingleOccurance = True
          for j in range((i + 1), n):
              if (arr[i] == arr[j]):
                  isSingleOccurance = False
                  arr[i] = arr[j] = 0
                  break
          if (isSingleOccurance == True):
              if (arr[i] > 0):
                  SubsetSum_1 += arr[i]
              else:
                  SubsetSum_2 += arr[i]
      return abs((SubsetSum_1 - SubsetSum_2))
source_cpp: int maximum_possible_difference_two_subsets_array(vector<int> arr, int n) {
    int SubsetSum_1 = 0, SubsetSum_2 = 0;
    for ( int i = 0;
    i <= n - 1;
    i ++ ) {
      bool isSingleOccurance = true;
      for ( int j = i + 1;
      j <= n - 1;
      j ++ ) {
        if ( arr [ i ] == arr [ j ] ) {
          isSingleOccurance = false;
          arr [ i ] = arr [ j ] = 0;
          break;
        }
      }
      if ( isSingleOccurance ) {
        if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ];
        else SubsetSum_2 += arr [ i ];
      }
    }
    return abs ( SubsetSum_1 - SubsetSum_2 );
  }
question_info.entry_fn_name: maximum_possible_difference_two_subsets_array
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({5, 14, 15, 21, 0, 0, 42, 0, 0, 0, 0, 48, 0, 0, 53, 60, 62, 69, 69, 79, 82, 86, 96}, 15, 198)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-54, 0, -22, 94, 58, 0, -12, 84, 0, 0, -34, 16, -10, -32, 50, -78, 68, -52, -64, 66, 0, 0, -38, -18, -84, -66, -36, 64, -12, 44, 48, 8, 42}, 28, 1100)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 1}, 2, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver({63, 49, 18, 36, 21, 30, 45, 87}, 6, 217)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-96, 0, 0, -72, -62, -56, -52, -44, 0, 0, -28, -22, -20, -12, 0, 0, -2, 2, 2, 4, 36, 44, 46, 50, 50, 54, 66, 92}, 18, 468)
      print(string.format("TEST-4...%s",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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0}, 34, 1)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 2, 8, 12, 0, 0, 14, 17, 18, 27, 28, 31, 34, 37, 38, 42, 43, 45, 49, 52, 53, 0, 0, 58, 62, 66, 71, 74, 87, 93, 96, 99}, 25, 671)
      print(string.format("TEST-6...%s",result))
  
      result = driver({0, -28, -30, 86, 0, -80, 76, -2, 28, 0, 0, 84, 0, 0, -88, 0, 42, 16, 0, 0, 78, -8, -46, -6, 0, 0, 0, -12, -32, -72, 84, -82, 76, -84, 80, -50, 90, -50, -14, -82, 78, 48, -10, 86, 34, -20, -76, 58}, 28, 710)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 1}, 1, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({83, 86, 57, 18, 98, 52, 1, 37, 11, 49, 10, 67, 2, 60, 30, 42, 8, 97, 25, 55, 5, 75, 9, 67}, 16, 703)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 198, "inputs": {"arr": [5, 14, 15, 21, 0, 0, 42, 0, 0, 0, 0, 48, 0, 0, 53, 60, 62, 69, 69, 79, 82, 86, 96], "n": 15}}, {"idx": 1, "outputs": 1100, "inputs": {"arr": [-54, 0, -22, 94, 58, 0, -12, 84, 0, 0, -34, 16, -10, -32, 50, -78, 68, -52, -64, 66, 0, 0, -38, -18, -84, -66, -36, 64, -12, 44, 48, 8, 42], "n": 28}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0, 0, 1], "n": 2}}, {"idx": 3, "outputs": 217, "inputs": {"arr": [63, 49, 18, 36, 21, 30, 45, 87], "n": 6}}, {"idx": 4, "outputs": 468, "inputs": {"arr": [-96, 0, 0, -72, -62, -56, -52, -44, 0, 0, -28, -22, -20, -12, 0, 0, -2, 2, 2, 4, 36, 44, 46, 50, 50, 54, 66, 92], "n": 18}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0], "n": 34}}, {"idx": 6, "outputs": 671, "inputs": {"arr": [1, 2, 8, 12, 0, 0, 14, 17, 18, 27, 28, 31, 34, 37, 38, 42, 43, 45, 49, 52, 53, 0, 0, 58, 62, 66, 71, 74, 87, 93, 96, 99], "n": 25}}, {"idx": 7, "outputs": 710, "inputs": {"arr": [0, -28, -30, 86, 0, -80, 76, -2, 28, 0, 0, 84, 0, 0, -88, 0, 42, 16, 0, 0, 78, -8, -46, -6, 0, 0, 0, -12, -32, -72, 84, -82, 76, -84, 80, -50, 90, -50, -14, -82, 78, 48, -10, 86, 34, -20, -76, 58], "n": 28}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 1], "n": 1}}, {"idx": 9, "outputs": 703, "inputs": {"arr": [83, 86, 57, 18, 98, 52, 1, 37, 11, 49, 10, 67, 2, 60, 30, 42, 8, 97, 25, 55, 5, 75, 9, 67], "n": 16}}]