# Easy c++ solution using map ,tree

#1

class node{
public:
int index;
int data;
node* left;
noderight;
};
node
newnode( int i , int k){
node* temp = new node();
temp->index =i;
temp->data = k;
temp->left=NULL;
temp->right=NULL;
return (temp);
}
node* insert(node* root , int i , int k){
if ( root == NULL){
root =newnode(i,k);
}else if (root ->data < k){
root->right = insert(root->right,i,k);
}else{
root->left = insert(root->left, i, k);
}
return root;
}
void inorder( node* root , vector &v){
if ( root == NULL)return ;
inorder(root->left , v);
v.push_back( root->index);
inorder( root->right, v);

}
vector Solution::solve(string A, vector &B) {
map<string , int >m;
string s="";
for ( int i=0;i<A.size();i++){
if ( A[i]!=’_’){
s.push_back(A[i]);
}else {
m[s]++;
s.clear();
}
}
m[s]++;

``````node* root=NULL;
for ( int i=0;i<B.size();i++){
string t = B[i];
int k =0;
string s="";
for ( int j=0;j<t.size();j++){
if ( t[j]!='_'){
s.push_back(t[j]);
}else {
if ( m.find(s)!=m.end())k++;
s.clear();
}
}
if ( m.find(s)!=m.end())k++;
root =insert(root,i,k);
``````

}
vector v;
inorder(root , v);
reverse( v.begin(),v.end());
return v;
}