#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–){
int n,k;
cin>>n>>k;
string s;
cin>>s;
int var=0;
int check=0;
int onecount[k]={0};
int zerocount[k]={0};
while(var<k)
{
for(int i=var;i<n;i+=k)
{
if(s[i]=='1')
onecount[var]++;
else zerocount[var]++;
}
if(onecount[var]%2==1)
check=1;
var++;
}
if(check==1){
int ans=0;
for(int i=0;i<k;i++){
ans+=zerocount[i];
}
cout<<ans<<endl;
}
else {
int ans1=0,ans0=0;
for(int i=0;i<k;i++){
ans1+=zerocount[i];
ans0+=onecount[i]/2;
}
cout<<min(ans1,ans0)<<endl;
}
}
return 0;
}
This is my way of approaching the problem but it shows wrong answer so I want to know which testcase it fails so that i can understand where I’m going wrong
problem link - Unique xor - Problems - CodeChef