#C7708. Maximum Festival Joy
Maximum Festival Joy
Maximum Festival Joy
You are given T test cases. For each test case, you are provided with an integer N
that represents the number of timestamp values, followed by N
space-separated integers. Your task is to compute the maximum possible product of any two distinct timestamps. If there are fewer than 2 timestamps in a test case, output 0
.
Formally, let the timestamps be sorted in non-decreasing order as \(a_1, a_2, \dots, a_N\). If \(N \ge 2\), then the maximum product is given by:
\[
a_{N-1} \times a_N
\]
Otherwise, the answer is 0
.
Make sure your solution reads input from standard input (stdin) and writes output to standard output (stdout).
inputFormat
The first line of input contains a single integer T
representing the number of test cases. The description of each test case follows:
- The first line of each test case contains an integer
N
(\(0 \leq N \leq 10^5\)), the number of timestamps. - The second line contains
N
space-separated integers representing the timestamps.
If N
is less than 2, then there are not enough timestamps to form a product. In that case, output 0
for that test case.
outputFormat
For each test case, output a single line containing one integer: the maximum product of any two distinct timestamps (or 0
if the number of timestamps is less than 2).
5
5
1 2 3 4 5
4
6 7 8 9
3
10 20 30
4
0 1 2 3
2
1 2
20
72
600
6
2
</p>