#K1646. Maximum Product of Two
Maximum Product of Two
Maximum Product of Two
You are given an array of integers. Your task is to determine the maximum product obtained by multiplying two distinct elements from the array. Formally, given an array (A) with (n) elements, you need to compute [ \max_{0 \leq i < j < n} { A[i] \times A[j] }. ] A common approach is to sort the array and consider the product of the two largest numbers as well as the product of the two smallest numbers (which could both be negative). Return the larger of the two products.
inputFormat
The input is read from standard input. The first line 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 second line contains (n) space-separated integers, which are the elements of the array.
outputFormat
For each test case, output a single line containing the maximum product of any two distinct elements in the array.## sample
3
2
1 5
4
1 2 3 4
3
-1 -2 -3
5
12
6
</p>