Simple solution without using Tree


#1

vector Solution::solve(string A, vector &B)
{
unordered_set s1;
int j=0;
int i=0;
while(i<A.size())
{
j=i;
string temp;
while(A[j]!=’’ && j<A.size())
{
temp+=A[j];
j++;
}
///cout<<temp<<" ";
i+=temp.size()+1;
s1.insert(temp);
}
multimap<int,int>m;
for(int k=0;k<B.size();k++)
{
string a=B[k];
int j=0;
int count=0;
int i=0;
while(i<a.size())
{
j=i;
string temp;
while(a[j]!=’
’ && j<a.size())
{
temp+=a[j];
j++;
}
//cout<<temp<<" “;
i+=temp.size()+1;
//s1.insert(temp);
if(s1.find(temp)!=s1.end())
count++;
//cout<<count<<” ";
}

    count*=(-1);
    m.insert({count,k});
}
//cout<<endl;
vector<int>ans;
for(auto i:m)
{
    //cout<<i.first<<" "<<i.second<<endl;
    ans.push_back(i.second);
}
//reverse(ans.begin(),ans.end());
return ans;

}