Most of coder did this program at O(n3) but I did it at O(n2), even sample test case is right but it is say WA…Please help!
#include
using namespace std;
int main() {
int i,K,c,d,n,T;
cin>>T;
char a[100];
for(i=1; i<=T; i++) {
cin>>n>>K;
c=0;
d=0;
for(int j=0;j<100;j++) a[j]=NULL;
for(int j=0;j<n;j++) {
cin>>a[j];
if(a[j] == 'H' && j>=n-K)
c++;
if(a[j] == 'H')
d++;
}
if(c%2==0) {
cout<<(d-c)<<endl;
}
else cout<<(n-K-d+c)<<endl;
}
return 0;
}