Very easy c++ solution using unordered map ;


#1

bool sortinrev(const pair<int,int> &a, const pair<int,int> &b)
{
if(a.first!=b.first)
return (a.first > b.first);
else
return (a.second < b.second);
}
vector Solution::solve(string A, vector &B) {
vector res;
unordered_map<string,int> mp;
stringstream ss(A);
string s;
while(getline(ss,s,’’))
mp[s]++;
vector<pair<int,int>> v;
for(int i=0;i<B.size();i++)
{
int c=0;
s.clear();
stringstream ss1(B[i]);
while(getline(ss1,s,’
’))
if(mp.find(s)!=mp.end())
c++;
v.push_back(make_pair(c,i));
}

sort(v.begin(),v.end(),sortinrev);
for(int i=0;i<v.size();i++)
res.push_back(v[i].second);
return res;

}