forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB0075.cpp
More file actions
43 lines (39 loc) · 710 Bytes
/
B0075.cpp
File metadata and controls
43 lines (39 loc) · 710 Bytes
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
// Problem Code: STICKS
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
int sticks(vector<int> A) {
vector<int> sides;
unordered_set<int> set;
unordered_set<int>::iterator it;
for(int i=0 ; i<A.size() ; i++) {
it = set.find(A[i]);
if(it != set.end()) {
sides.push_back(A[i]);
set.erase(it);
}
else
set.insert(A[i]);
}
if(sides.size() < 2)
return -1;
sort(sides.rbegin(), sides.rend());
return sides[0]*sides[1];
}
int main() {
int T, N, num;
vector<int> A;
cin >> T;
while(T--) {
cin >> N;
for(int i=0 ; i<N ; i++) {
cin >> num;
A.push_back(num);
}
cout << sticks(A) << endl;
A.clear();
}
return 0;
}