title: Maximum Triplet Sum Array 2
signature: maximum_triplet_sum_array_2 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 7L, 12L, 21L, 22L, 25L, 27L, 28L, 28L, 31L, 32L, 32L, 41L, 45L, 47L, 51L, 53L, 60L, 61L, 61L, 63L, 71L, 74L, 82L, 83L, 85L, 88L, 92L, 96L, 96L), 28L, 
          265L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-52L, 26L, 74L, -62L, -76L), 2L, 
          -100000026L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 11L, 
          3L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(63L, 71L, 15L, 28L, 31L, 84L, 8L, 17L, 24L, 42L, 66L, 95L, 30L), 6L, 
          218L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -92L, -92L, -90L, -88L, -88L, -86L, -82L, -80L, -78L, -66L, -54L, -52L, -52L, -46L, -46L, -42L, -36L, -32L, -24L, -24L, -14L, -14L, -14L, -12L, -10L, 0L, 6L, 8L, 20L, 24L, 24L, 28L, 38L, 38L, 52L, 54L, 56L, 64L, 74L, 74L, 76L, 82L, 94L, 94L), 31L, 
          52L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L), 30L, 
          3L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(15L, 19L, 80L), 2L, 
          -99999966L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(4L, 80L, 18L, 74L, 36L, -30L, -72L, -28L, -32L, -16L, -8L, 38L, 78L, -48L, 98L, -64L, 86L, -60L, -44L, 84L, -98L, 40L, 14L, 30L, 44L, 90L, -30L, -42L, 24L, -28L, 24L, 40L, -96L, 98L, 90L, -68L, -54L, -52L, 62L, 34L, -98L, 68L, -56L, -94L, -78L, -12L, 28L), 41L, 
          286L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 1L, 1L, 1L, 1L, 1L), 3L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(2L, 18L, 96L, 7L, 99L, 83L, 3L, 88L, 23L, 77L, 6L, 28L, 55L, 49L, 69L, 55L, 48L, 76L, 43L, 11L, 43L, 44L, 17L, 74L, 27L, 64L, 76L, 77L, 53L, 26L, 73L, 12L, 19L, 62L, 18L, 34L, 13L, 31L, 97L, 96L, 85L, 27L, 30L, 97L, 89L, 25L), 41L, 
          292L
      )))
  
  }
  
  main()
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 );
  }