Strings--string compression

one test case is failing…whyyy???
#include
#include
using namespace std;

void stringcompress(char a[]){
int freq[26]={0};
int len=strlen(a);
int cnt=0;
int j=0;
while(j<len){
freq[a[j]-‘a’]++;
j++;
}

for(int i=0 ; i<26 ; i++){
	if(freq[i]>0){
	char x = i+'a';
	if(freq[i]==1){

	cout<<x;
	}
else{
	cout<<x<<freq[i];

	}
}

}
}
// using namespace std;
int main(){
char a[1000];
cin.getline(a,1000);
stringcompress(a);
// int freq[26]={0};

return 0;

}

hi @abhinavssr2003_eab0717682969e5c,
you r counting all instance at once thats not the way
for test case aaabbaa answer is a3b2a2 but since you r counting all at once it’s giving a5b2

correction --> count till one single char comes then for next char count from 0

okay…Will you provide me the code

@abhinavssr2003_eab0717682969e5c sure refer https://ide.codingblocks.com/s/661048
correction of your code --> count till one single char comes then for next char count from 0

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.