Did it without hashmap by generating all possible ways of selecting four indexes


#1

bool solve(vector &flag,int i,int idx,int count,vector A){
if(count==i){
if(A[flag[0]]+A[flag[1]]==A[flag[2]]+A[flag[3]]){
return true;
}
return false;
}
for(int j=idx;j<A.size();j++){
if(i==2 && idx-1>=2){
for(int k=flag[0]+1;k<idx-1;k++){
flag.push_back(k);
if(solve(flag,i+1,idx,count,A))
return true;
flag.pop_back();
}
}
flag.push_back(j);
if(solve(flag,i+1,j+1,count,A))
return true;
flag.pop_back();
}
return false;
}

vector Solution::equal(vector &A) {
vector ans;
solve(ans,0,0,4,A);
return ans;
}