My issue
how the answer is 1 for:
1
2 3
aa
aba
shouldn’t it be 2 ?
My code
#include<iostream>
#define ll long long
using namespace std;
void fun(string &s1, string &s2){
int ans=0;
int a=s1.size(), b=s2.size();
bool flag=false;
int i=0, j=0;
while(i<a && j<b){
if(s1[i] != s2[j]){
if(i>0) ans=2;
else{
flag=true;
ans=-1;
}
break;
}
++i;++j;
}
if(a!=b && ans==0 && flag==false) ans=1;
cout<<ans<<"\n";
}
int main(){
int t;
cin>>t;
for(int q=0;q<t;++q){
int a,b;
cin>>a>>b;
string s1,s2;
cin>>s1;
cin>>s2;
fun(s1,s2);
}
return 0;
}
Problem Link: Replace With First Practice Coding Problem