Hi everyone In contest This Question the solution i wrote . But now i am not able to find the logical mistake please help me to find logical mistake.
thanks in advance here is code
...
#include<iostream>
using namespace std;
#define ll long long int
int main(){
ll t ;
cin>>t;
while(t--){
ll n ,k;
cin>>n>>k;
string s;
cin>>s;
ll lastX=-1,lastS=-1;
ll count=0;
ll last=-1,i;
for(i=0;i<n;i++){
if(s[i]=='*'){
s[i]='x';
lastX=i;
count++;
break;
}
}
for(i=n-1;i>=0;i--){
if(s[i]=='*'){
last=i;
count++;
s[i]='x';
break;
}
}
if(last==-1 || last — lastX<=k){
cout<<count<<endl;
}
else{
for(i=0;i<n;i++){
if(s[i]=='*'){
if(i-lastX<k){
lastS=i;
}
else if((i-lastX==k))
{
s[i]='x';
lastX=i;
lastS=-1;
count++;
}
else{
s[lastS]='x';
lastX=lastS;
lastS=-1;
count++;
}
}
}
if(last-lastX>k&&lastS!=-1){
count++;
}
cout<<count<<endl;
}
}
}
...