Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given an array, the task is to find the maximum triplet sum in the array.

**Example 1:**

**â€‹Input :** arr[ ] = {1, 2, 3, 5}
**Output :** 10
**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 6, 8, 9, and 10.
The maximum sum is 10.

**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}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Maximum triplet sum in array

...