X DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Maximum triplet sum in array
Basic Accuracy: 67.41% Submissions: 2048 Points: 1

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

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 ≤ 105
-105 ≤ A[i] ≤ 105

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

Editorial

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

My Submissions:  