Three Great Candidates
Easy Accuracy: 12.2% Submissions: 514 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.


Your Task:
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

 

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window