Problem Statement Link :- NAME1
/* Approach :- I stored both parent names character count in a map (mp) and then while iterating through their child strings I am storing the character count of their children in a separate map (mpChild) and then at each point checking that whether the character count of a particular character in mpChild is exceeding the character count of that particular character in mp and if its exceeding the final output will be βNOβ otherwise at end the final output will be βYESβ. */
Code :-
#include<bits/stdc++.h>
using namespace std;
void solve() {
string a, b;
cin >> a >> b;
map<char,int> mp, mpChild;
for(int i=0; i<a.size(); i++){
mp[a[i]]++;
}
for(int i=0; i<b.size(); i++){
mp[b[i]]++;
}
int n;
cin >> n;
string name;
for(int i=0; i<n; i++){
cin >> name;
for(int j=0; j<name.size(); j++){
mpChild[name[j]]++;
if (mpChild[name[j]] > mp[name[j]]){
cout << "NO" << endl;
return;
}
}
}
cout << "YES" << endl;
}
int main() {
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}