Question broken?

freq of characters in a string:

#include
#include

using namespace std;

void freq(string s){
int fre[26]={0};
char result;
int len=s.length();

for(int i=0;i<len;++i){
	fre[s[i]-'a']++;
}
for(int i=0;i<26;++i){
	if(fre[i]>0){
	result=(char)(i + 'a');
	cout<<result<<fre[i];
	}
}

}
int main() {
string s;
getline(cin,s);
freq(s);
return 0;
}

hello @granthdhir
u have to compress only consecutive same character.

for example->
aaaabba will be compressed as
a4b2a1

I solved the problem with the following code :

https://ide.codingblocks.com/s/479656 ,is there a better approach to the problem?

no, this is efficient.

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.