title: Maximum Triplet Sum Array 2
signature: func maximumTripletSumArray2(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{4, 7, 12, 21, 22, 25, 27, 28, 28, 31, 32, 32, 41, 45, 47, 51, 53, 60, 61, 61, 63, 71, 74, 82, 83, 85, 88, 92, 96, 96}, 
  	28, 265)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-52, 26, 74, -62, -76}, 
  	2, -100000026)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	11, 3)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{63, 71, 15, 28, 31, 84, 8, 17, 24, 42, 66, 95, 30}, 
  	6, 218)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-94, -92, -92, -90, -88, -88, -86, -82, -80, -78, -66, -54, -52, -52, -46, -46, -42, -36, -32, -24, -24, -14, -14, -14, -12, -10, 0, 6, 8, 20, 24, 24, 28, 38, 38, 52, 54, 56, 64, 74, 74, 76, 82, 94, 94}, 
  	31, 52)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0}, 
  	30, 3)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{15, 19, 80}, 
  	2, -99999966)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{4, 80, 18, 74, 36, -30, -72, -28, -32, -16, -8, 38, 78, -48, 98, -64, 86, -60, -44, 84, -98, 40, 14, 30, 44, 90, -30, -42, 24, -28, 24, 40, -96, 98, 90, -68, -54, -52, 62, 34, -98, 68, -56, -94, -78, -12, 28}, 
  	41, 286)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{0, 1, 1, 1, 1, 1}, 
  	3, 2)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{2, 18, 96, 7, 99, 83, 3, 88, 23, 77, 6, 28, 55, 49, 69, 55, 48, 76, 43, 11, 43, 44, 17, 74, 27, 64, 76, 77, 53, 26, 73, 12, 19, 62, 18, 34, 13, 31, 97, 96, 85, 27, 30, 97, 89, 25}, 
  	41, 292)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def maximum_triplet_sum_array_2(arr, n):
      maxA = (- 100000000)
      maxB = (- 100000000)
      maxC = (- 100000000)
      for i in range(0, n):
          if (arr[i] > maxA):
              maxC = maxB
              maxB = maxA
              maxA = arr[i]
          elif (arr[i] > maxB):
              maxC = maxB
              maxB = arr[i]
          elif (arr[i] > maxC):
              maxC = arr[i]
      return ((maxA + maxB) + maxC)
source_cpp: int maximum_triplet_sum_array_2(vector<int> arr, int n) {
    int maxA = INT_MIN, maxB = INT_MIN, maxC = INT_MIN;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] > maxA ) {
        maxC = maxB;
        maxB = maxA;
        maxA = arr [ i ];
      }
      else if ( arr [ i ] > maxB ) {
        maxC = maxB;
        maxB = arr [ i ];
      }
      else if ( arr [ i ] > maxC ) maxC = arr [ i ];
    }
    return ( maxA + maxB + maxC );
  }