Showing:
Handle Score
@Ibrahim Nash 5765
@akhayrutdinov 5111
@mb1973 4993
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Pair with greatest product in array
Easy Accuracy: 7.84% Submissions: 51 Points: 2

Given an array A of N elements. The task is to find the greatest number S such that it is product of two elements of given array (S cannot be included in pair. Also, pair must be from different indices).

Example 1:

Input :  arr[] = {10, 3, 5, 30, 35}
Output:  30
Explanation: 30 is the product of 10 and 3.

Example 2:
Input :  arr[] = {2, 5, 7, 8}
Output:  -1
Explanation: Since, no such element exists.


Example 3:
Input  :  arr[] = {10, 2, 4, 30, 35}
Output:  -1


Example 4:
Input :  arr[] = {10, 2, 2, 4, 30, 35}
Output:  4

Example 5:
Input  : arr[] = {17, 2, 1, 35, 30}
Output : 35

You don't need to read input or print anything. Your task is to complete the function findGreatest() which takes the array arr[] and its size N as inputs and returns the answer. If the answer is not present in the array, return -1.

Expected Time Complexity: O(N. Log(N))
Expected Auxiliary Space: O(N)

Constraints:
1 ≤ N ≤ 106
1 ≤ Ai ≤ 107

### Editorial

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

#### My Submissions:

Pair with greatest product in array