please give a tougher test cases…why accepting O(n^4) solution
Why they accepting O(n^4) solution...atleast force solver for n^3
hey!
just checkout this O(n^2) solution…
vector Solution::equal(vector &A)
{
vectorsol;
unordered_map<int,pair<int,int>>mp;
vector<vector>vec;
for(int i=0;i<A.size();i++)
{
for(int j=i+1;j<A.size();j++)
{
mp.insert({A[i]+A[j],{i,j}});
}
}
for(int i=1;i<A.size();i++)
{
for(int j=i+1;j<A.size();j++)
{
int sum=A[i]+A[j];
if(mp.find(sum)!=mp.end())
{
int a=mp[sum].first;
int b=mp[sum].second;
if(a<i && b!=j && b!=i)
{
sol={a,b,i,j};
vec.push_back(sol);
}
}
}
}
sort(vec.begin(),vec.end());
return vec[0];
}