-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeeks_maximum_product_in_array.cpp
More file actions
60 lines (48 loc) · 1.17 KB
/
Copy pathgeeks_maximum_product_in_array.cpp
File metadata and controls
60 lines (48 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
https://practice.geeksforgeeks.org/problems/maximum-product-of-two-numbers/0
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.
** For More Input/Output Examples Use 'Expected Output' option **
*/
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for(int z=0;z<t;z++)
{
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++)
{
cin >> a[i];
}
sort(a,a+n);
int mul1=a[0]*a[1];
int mul2=a[n-1]*a[n-2];
if(mul1>mul2)
cout<<mul1<<endl;
else
cout<<mul2<<endl;
}
return 0;
}