Its not passing few test cases

#include

using namespace std;

int main()
{
string s;
cin>>s;
int freq[26]={0};
for(auto ch:s){
freq[ch-‘a’]++;
}
for(int i=0;i<26;i++){
int mg=freq[i];
if(mg>0)
{

 cout<<(char)('a'+i)<<freq[i];
     
   }

}

return 0;

}

for input aaabbbaaa answer should be a3b3a3, but your answer would be a6b3, we have to solve for local clusters.

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.