P20795 [GeeksforGeeks] D54c71dc974b7db3a200eb63f34e3d1cba955d86
普及
题目描述

Given an array arr of size n, the task is to find the maximum triplet product in the array.
Example 1:
Input:
n = 4
arr[] = {1, 2, 3, 5}
Output:
30
Explanation:
532 gives 30. This is the maximum possible
triplet product in the array.
Example 2:
Input:
n = 7
arr[] = {-3, -5, 1, 0, 8, 3, -2}
Output:
120
Explanation:
-3-58 gives 120. This is the maximum possible triplet product in the array.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxTripletProduct() which takes an integer n and an array arr and returns the maximum triplet product in the array.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Constraints:
3 ≤ N ≤ 5*10^{5}
-10^{6} ≤ A[i] ≤ 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
n = 4 arr[] = {1, 2, 3, 5}
样例输出
30