#C11767. Maximum Product of Array Elements
Maximum Product of Array Elements
Maximum Product of Array Elements
You are given several test cases. In each test case, you are provided with an array of integers. Your task is to determine the maximum product of two elements from the array. Note that the two elements can be the same element (i.e. pairing an element with itself is allowed).
Formally, given an array \(a_1, a_2, \dots, a_n\), you need to compute the value:
[ \max_{1 \le i, j \le n} {a_i \times a_j} ]
Note: If the array contains only one element, then the answer is the element multiplied by itself.
It is guaranteed that each test case contains at least one element.
inputFormat
The input is given via standard input and is structured as follows:
- An integer \(T\) representing the number of test cases.
- For each test case:
- An integer \(n\) representing the number of elements in the array.
- A line containing \(n\) space-separated integers.
Consider that the input is read from stdin
.
outputFormat
For each test case, output the maximum product on a separate line to stdout
.
3
5
1 3 5 2 4
3
10 20 30
4
7 2 3 9
25
900
81
</p>