#K7461. Maximum Product of Two Distinct Numbers
Maximum Product of Two Distinct Numbers
Maximum Product of Two Distinct Numbers
You are given an array of integers. Your task is to find the maximum product obtained by multiplying two distinct elements from the array. In mathematical terms, for an array \(A\) with \(N\) elements, you need to compute:
\(\max_{1 \le i < j \le N} (A_i \times A_j)\)
This problem requires special attention to negative numbers because the product of two negative numbers might be positive and even larger than the product of the two largest positive numbers.
inputFormat
The first line of input contains a single integer \(T\) representing the number of test cases. For each test case, the first line contains an integer \(N\) denoting the number of elements in the array. The next line contains \(N\) space-separated integers representing the array elements.
Example:
2 4 1 20 30 4 3 -10 -3 5
outputFormat
For each test case, output a single integer which is the maximum product obtained by multiplying two distinct elements from the array. Output the result of each test case on a new line.
Example Output:
600 30## sample
2
4
1 20 30 4
3
-10 -3 5
600
30
</p>