Here’s the link - https://www.codechef.com/problems/STRBIT
THANKS IN ADVANCE !!!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int t;cin>>t;
while(t--){
int n,k;cin>>n>>k;
char s[100001];scanf("%s" , s);
int ans=0,flip =0;
vector<int> mark(n*2+1);
for(int i=0;i<n;i++){
flip+=mark[i];
if((s[i]=='R' && (flip%2)==0) || (s[i]=='G' && (flip%2)==1))
{
mark[i+1]++;
mark[i+k]--;
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}