Maximum product of two numbers (GFG)
Given an array with all elements greater than or equal to zero. Return the maximum product of two numbers possible.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N, size of array. The second line of each test case contains array elements.
Output:
Print the maximum product of two numbers possible.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 107
0 ≤ A[i] ≤ 104
Example:
Input:
1
5
1 100 42 4 23
Output:
4200
Explanation:
Testcase 1: Two maximum numbers are 100 and 42 and their product is 4200.
SOLUTION:
for i in range (int(input())):
n=int(input())
p=list(map(int,input().split()))
p=sorted(p)
print(p[-1]*p[-2])
Comments
Post a Comment