Three Great Candidates
Easy Accuracy: 19.96% Submissions: 4033 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:

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

Example 2:

N = 5
Arr[] = {-10, -3, -5, -6, -20}
Output: -90
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)

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


We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

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?


All Submissions

My Submissions:

Login to access your submissions.

Three Great Candidates

Output Window