Pair with greatest product in array
Submissions: 4684   Accuracy:

22.48%

  Difficulty: Easy   Marks: 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).

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N denoting size of the array. Then in the next line are n space separated values of the array.

Output:
For each test case in a new line print the required output.

Constraints:
1 <= T <= 100
1 <= N <= 106
1 <= Ai <= 107

Example:
Input:

2
4
2 5 7 8
6
10 2 2 4 30 35

Output:
-1
4

Explanation:
Testcase 2
: 4 is the greatest element whose pair product (2, 2) is also present in array.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.