Maximum product of two numbers
Basic Accuracy: 57.97% Submissions: 3727 Points: 1

Given an array Arr of size N with all elements greater than or equal to zero. Return the maximum product of two numbers possible.

Example 1:

N = 6
Arr[] = {1, 4, 3, 6, 7, 0}  
Output: 42

Example 2:

N = 5
Arr = {1, 100, 42, 4, 23}
Output: 4200

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 n as parameters and returns an integer denoting the answer.

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

2 ≤ N ≤ 107
0 ≤ Arr[i] ≤ 104


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.

Maximum product of two numbers

Output Window