What's wrong with this solution for NAME2

enter code here
#include
using namespace std;
main()
{
int t = 0 ;
cin>>t;
while(t–)
{
string a = “”;
string b = “”;
cin>>a>>b;
int j = 0 ;
for(int i = 0 ; i < b.length();i++)
{
if(a[j]==b[i])
{
j++;
}
}
if(j==a.length())
{
cout<<“YES”<<endl;
}
else
{
cout<<“NO”<<endl;
}
}
return 0 ;
}

All test cases ran fine .

It would be better if you include the problem link as well !! Nobody can help without the problem statement…

The cases wrong with your code are of types where string a is of greater length than string b . Lets say-

Input
1
abracadzabraz zz

You will just iterate through string b searching for string a, which cant be true. Make a universal condition that you will iterate through string of greater length and try to find string of lesser length.

Add a section to your code to see if a.length()>b.length() , and if true, then simply swap the 2 strings (this will ensure that b is always the larger string!)

Thanks mate

1 Like
//