Code is given below

#include<bits/stdc++.h>
using namespace std;
int main() {
string str;
map<char,int>m;
getline(cin,str);
int n=str.length();
for(int i=0;i<n;i++)
{
m[str[i]]++;
}
map<char,int> ::iterator itr;
for(itr=m.begin();itr!=m.end();itr++)
{
cout<first<second;
}
return 0;
}

@CHANDU_0556 you need to compress only the local clusters for example if the given string was aaabbbaaa answer would be a3b3a3, but your logic would give a6b3.

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.