#K66597. Largest Product of Two

    ID: 32455 Type: Default 1000ms 256MiB

Largest Product of Two

Largest Product of Two

You are given several test cases. In each test case, you are provided with an integer N and an array of N integers. Your task is to compute the largest product that can be obtained by multiplying two distinct numbers from the array.

More formally, for an array \(a_1, a_2, \dots, a_N\), you are to find \[ \max_{1 \le i < j \le N} (a_i \times a_j), \] and output the result for each test case.

The input format is as follows:

  • The first line contains an integer T, the number of test cases.
  • For each test case, the first line contains an integer N.
  • The next line contains N space-separated integers.

Print the answer for each test case on a new line.

inputFormat

The input begins with an integer T indicating the number of test cases. For each test case, the first line contains an integer N denoting the size of the array, followed by a line with N space-separated integers.

Example:

5
5
10 -20 5 -10 7
4
1 2 3 4
3
-1 -2 -3
2
-1 1
5
0 0 0 0 0

outputFormat

For each test case, print one integer — the maximum product of two distinct numbers in the given array. Each result should be printed on a new line.

Example:

200
12
6
-1
0
## sample
1
2
-1 5
-5

</p>