String compression problem

#include<bits/stdc++.h>
using namespace std;

int main() {

string a,b,v;
cin>>a;

sort(a.begin(),a.end());

b=a;

b.erase(unique(b.begin(), b.end()),b.end()); 

for(int i=0 ; i <b.length();i++)
{
	int n= count (a.begin(),a.end(),b[i]);
		cout << b[i]<<n;

}

return 0;

}

I would like to know what is wrong in this problem ?
out of 4 test cases , There are 2 test cases are passed but test 2 test case got failed. Please advise.

hi @chellapandiyan please share your code by saving it on CB IDE

Hi Ishitagambhir,

file name : stringcompression.cpp

input : aaabbccds
output : a3b2c2d1s1

but when i submit there are 2 test case got failed.

hi @chellapandiyan for input aabbaa
the output should be a2b2a2
and your output is a4b2

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.