title: Maximum Possible Difference Two Subsets Array
signature: func maximumPossibleDifferenceTwoSubsetsArray(arr []int, n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{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)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 1}, 
  	2, 0)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{63, 49, 18, 36, 21, 30, 45, 87}, 
  	6, 217)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 1}, 
  	1, 0)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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 );
  }