A very interesting question needs help !!

Question link : Programming tutorials, Coding problems, and Practice questions

NOTE: my input : 2 sumut sumu sumit sumit gives output NO NO but it shud give NO YES . //i have problem in this.

MY CODE::

#include

#include

using namespace std;

int main()

{

int t;

cin>>t;

string s1[t],s2[t];

long int a[26]={0},l[t]={0};

for(int i=0;i<t;i++)

{

cin>>s1[i]>>s2[i];

}

for(int k=0;k<t;k++)

{

for(char i=‘a’;i<‘z’;i++)

{

for(int j=0;j<s1[k].size();j++)

{

if(s1[k].at(j)==i){a[i-97]++;}

}

for(int j=0;j<s2[k].size();j++)

{

if(s2[k].at(j)==i){a[i-97]–;}

}

}

for(int i=0;i<26;i++)

{

if(a[i]==0){l[k]++;}

}

}

for(int k=0;k<t;k++)

{

if(l[k]==26){cout<<endl<<“YES”;}

else{cout<<endl<<“NO”;}

}

return 0;

}

You Haven’t initialized the a[] to 0 for the remaining test cases.

Initially it’s 0, and hence you are getting correct output for test case 1. (Your Output is YES for the input:1 sumit sumit)

Just make all 26 values 0 in every test case.

Also, change your i<‘z’ to i<=‘z’.

Thanks, I got it :slight_smile: