title: Maximum Triplet Sum Array 2
signature: pub fn maximum_triplet_sum_array_2(arr: Vec<i32>, n: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(arr: Vec<i32>, n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([-52, 26, 74, -62, -76]), 2, 
        -100000026
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 11, 
        3
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([63, 71, 15, 28, 31, 84, 8, 17, 24, 42, 66, 95, 30]), 6, 
        218
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([15, 19, 80]), 2, 
        -99999966
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([0, 1, 1, 1, 1, 1]), 3, 
        2
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([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
      ));
      
  }
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 );
  }