Help me in solving NAME1 problem; I am not able to understand why my solution is incorrect?

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 :-

using namespace std;

void solve() {

string a, b;
cin >> a >> b;
map<char,int> mp, mpChild;

for(int i=0; i<a.size(); i++){

for(int i=0; i<b.size(); i++){

int n;
cin >> n;

string name;

for(int i=0; i<n; i++){
    cin >> name;
    for(int j=0; j<name.size(); j++){
        if (mpChild[name[j]] > mp[name[j]]){
            cout << "NO" << endl;

cout << "YES" << endl;


int main() {

int t;
cin >> t;

while(t--) {

return 0;


U are making mistake like when u are taking the inputs of name strings then when u will get the NO it will return the program and ignores rest inputs .
That is why u r getting wrong answer.

1 Like

Thankyou very very much for pointing out the mistake. I was really commiting a silly blunder.