title: Maximum Triplet Sum Array
signature: function maximum_triplet_sum_array(arr, n)
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({6, 10, 14, 19, 24, 29, 42, 43, 44, 47, 47, 55, 57, 59, 60, 61, 76, 76, 77, 81, 84, 92, 92, 93, 95, 97}, 15, 176)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-98, 72, 52, -62, 74, -26, -82, -74, 90, 58, 94, -2, 76, -28, 12, 64, -94, 86, 56, 10, 40, 20, 92, -4, -80, 26, -40, 36, 66, -46, 4, -42, -76, 76, -90, -48, 22, 30, 48, 38, 78}, 28, 276)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 3)
      print(string.format("TEST-2...%s",result))
  
      result = driver({96, 96, 38, 26, 2, 36, 15, 51, 78, 98, 94, 31, 62, 21, 7, 68, 37, 4}, 10, 290)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-8, 12, 68, 78, 78}, 4, 158)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 35, 3)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 15, 16, 17, 28, 28, 28, 30, 31, 37, 38, 38, 45, 45, 46, 46, 50, 51, 53, 53, 55, 55, 56, 58, 58, 64, 78, 82, 82, 85, 87, 89, 89, 90, 94, 95}, 29, 242)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-56, -72, -20, 88, 20, 86, 30, 36, -44, -66, -26, -88, 12, -76, 78, 62, 62, 68, -34, 0, -22, 64, 72, 56, -64, -16, -4, 86, 0, 98, -70, 98, -68, 92, -84, -56, 28, -74, 6, -10, -82, 36, -12, -26, 66, -60, -68, 70, 2}, 36, 288)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 11, 2)
      print(string.format("TEST-8...%s",result))
  
      result = driver({85, 31, 15, 68, 92, 89, 32, 56, 27, 70, 82, 58, 63, 83, 89, 95, 78, 9, 27, 34, 24, 42, 66, 6, 1, 71, 55, 23, 75, 26, 19, 58, 25}, 16, 276)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def maximum_triplet_sum_array(arr, n):
      sm = (- 1000000)
      for i in range(0, n):
          for j in range((i + 1), n):
              for k in range((j + 1), n):
                  if (sm < ((arr[i] + arr[j]) + arr[k])):
                      sm = ((arr[i] + arr[j]) + arr[k])
      return sm
source_cpp: int maximum_triplet_sum_array(vector<int> arr, int n) {
    int sum = INT_MIN;
    for ( int i = 0;
    i < n;
    i ++ ) for ( int j = i + 1;
    j < n;
    j ++ ) for ( int k = j + 1;
    k < n;
    k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ];
    return sum;
  }