Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Three Great Candidates
Easy Accuracy: 17.88% Submissions: 1392 Points: 2

The hiring team aims to find 3 candidates who are great collectively. Each candidate has his or her ability expressed as an integer. 3 candidates are great collectively if product of their abilities is maximum. Given abilities of N candidates in an array arr[], find the maximum collective ability from the given pool of candidates.

Example 1:

Input:
N = 5
Arr[] = {10, 3, 5, 6, 20}
Output: 1200
Explanation: Multiplication of 10, 6 and 20 is 1200.

Example 2:

Input:
N = 5
Arr[] = {-10, -3, -5, -6, -20}
Output: -90
Explanation: Multiplication of -3, -5 and -6 is -90.

You don't need to read input or print anything. Your task is to complete the function maxProduct() which takes the array of integers arr[] and as input parameters and returns the maximum product.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Constraints:
3 ≤ N ≤ 107
-105 ≤ Arr[i] ≤ 105