Error in this code? one test case is not running

#include
#include

using namespace std;

void compression(char a[]){
int b[26]={0};
for(int i=0;i<strlen(a);i++){
int index=a[i]-‘a’;
b[index]++;
}
int j=0;
int k=0;
while(j<strlen(a)){
k=a[j]-‘a’;
if(a[j]!=a[j+1]&&b[k]>0){
cout<<a[j];
if(b[k]>1){
cout<<b[k];
b[k]=0;
}
}
j++;
}
}

int main() {
char a[1005];
cin.getline(a,1005);
compression(a);

return 0;

}

Hi @umnah1103_2205d5eee7973385,
If the string is aabbcca

Your output: a3b2c2
Correct Output: a2b2c2a

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.