I am unable to understand ,what's wrong in the code for NAME2 question. Help needed


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;cin>>t;
while(t–)
{
string a,b;cin>>a>>b;long long int c=0;
for(int i=0;i<a.size();i++)
{
for(int j=0;j<b.size();j++)
{
if(a[i]==b[j])
{
c++;
break;
}
}
}
if(a.size()==c || b.size()==c)
cout<<“YES”<<"\n";
else
cout<<“NO”<<"\n";
}
return 0;
}

Please share the question .Otherwise how shall anyone help you?

1 Like

First you should format your code.

Try TC- 1 aab abc
Problem is you are always iterating from j=0.

Consider test case:
1
ab a
your output: YES
correct output: NO /* as "ab" is not a subsequence of "a" */

I think you should first read about subsequences!!

okay thanks!