题目描述
Given an array, the task is to find the maximum triplet sum in the array.
Example 1:
Input : arr[ ] = {4, 2, 7, 9}
Output : 20
Explanation:
Here are total 4 combination:
(0, 1, 2),(0, 1, 3),(0, 2, 3),(1, 2, 3).
So, the Sum of these combinations is
13,15, 20,and 18.The maximum sum is 20.
Example 2:
Input : arr[ ] = {1, 0, 8, 6, 4, 2}
Output : 18
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function maxTripletSum() that takes an array (arr), sizeOfArray (n), and return the maximum triplet sum in the array. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
3 ≤ N ≤ 10^{5}
-10^{5} ≤ A[i] ≤ 10^{5}
输入格式
见题面
输出格式
见题面