Problem Link : problem

solution link : solution

Any help appreciated

Index increment only when its having wrong answer . when there’s ‘N’ you should simply skip that. and when the last element matches you should increment or else do nothing.

**your modified code - **

```
#include<bits/stdc++.h>
using namespace std;
int main()
{
int p,q,r,t,n;
cin>>t;
while(t)
{
int c=0;
cin>>n;
char a[n],b[n];
cin>>a;
cin>>b;
for(int i=0;i<n;i++){
if(b[i]!='N'){
if(a[i]==b[i] && i == n-1){
c++;}
else if(a[i]!=b[i])
i++;
else c++;
}
}
cout<<c<<endl;
t--;
}
return 0;
}
```

ps: dont depend on others as they also busy in debugging their own codes.

1 Like

That’s exactly what the following else if does

```
else if(b[i]!='N'&&a[i]!=b[i]&&i<n-2)
i++;
```

This ensures increment only happens when character in **a** and **b** are not equal and **b** is not N.

I found the problem with my code and it had nothing to do with what you said. The problem was with for loop that went only up to n-2nd iteration starting from 0 ,which means if the n-2nd element is wrong then n-1th element(last element) won’t be skipped resulting in to wrong answer.