problem statement is here
#include<stdio.h>
#include<string.h>
int main(){
long int a,b,t,i,j,sum,n,u,k;
scanf("%ld",&t);
while(t--){
j=1;
sum=0;b=0;u=0;
char ar[25000];
scanf("%ld %ld",&n,&k);
scanf("%s",ar);
for(i=0;i<n;i++){
if(ar[i]>96 && ar[i]<123){
if(ar[i]==u){
b++;
if(b==k){
j=0;
b=0;
u=0;
}
}else{
sum++;
u=ar[i];
b=1;
if(b==k){
j=0;
b=0;
u=0;
}
}
}
}
if(j==1){
printf("-1\n");
}else{
printf("%ld\n",sum);
}
}
return 0;
}
this is a wrong solution your code fails at following input:
ReplyDelete5 3
rgggr
your code output:-1
correct output:3
your code is wrong
ReplyDeletetest case for which it fails:
5 3
rgggr
code output:-1
correct output:3
your code is wrong
ReplyDeletetest case for which it fails:
5 3
rgggr
code output:-1
correct output:3