#include <bits/stdc++.h>
using namespace std;
int t,n,l,res;
int length,breadth;
int temp;
int main()
{
cin>>t;
for(int k=0;k<(t);++k){
res=-1;
temp=0;
length=0;
breadth=0;
cin>>n;
int lengths[n];
for(int i =0;i<n;++i)
{
lengths[i]=0;
}
for(int i=0;i<n;++i){
cin>>lengths[i];
}
sort(lengths,lengths+n);
for(int i=n-1;i>0;--i){
if(count(lengths,lengths+n,lengths[i])<2){
continue;
}else if(temp==0){
length=lengths[i];
++temp;
int currcount = count(lengths,lengths+n,lengths[i]);
for(int m=0;m<currcount;++m)
{
--i;
}
++i;
}else if(temp==1){
breadth=lengths[i];
++temp;
}
else if(temp==2){
break;
}else{
res=-1;
}
}
res=length*breadth;
if(res==0){
res=-1;
}
cout<<res<<"\n";
}
}
I tried to debug my code and finally solved the test cases. but there is some limitation in this code i think… Anyone Help Please?