My issue
include
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,k;
cin>>n>>k;
string s,t;
cin>>s>>t;
int cnt=0;
for(int i=0;i<n;i++){
if(s[i]!=t[i]) cnt++;
}
if(cnt%2==1 || cnt/2 > k){
cout<<“NO\n”;
}
else if((cnt/2 == k))
cout<<“YES\n”;
else if(cnt/2<k && (n-cnt)>1)
cout<<“YES\n”;
else
cout<<“NO\n”;
}
return 0;
}
Can anyone tell me what was the issue in this code.
My code
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
string s,t;
cin>>s>>t;
int cnt=0;
for(int i=0;i<n;i++){
if(s[i]!=t[i]) cnt++;
}
if(cnt%2==1 || cnt/2 > k){
cout<<"NO\n";
}
else if((cnt/2 == k))
cout<<"YES\n";
else if(cnt/2<k && (n-cnt)>1)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
Problem Link: Binary Conversion Practice Coding Problem