Unable to pass TestCase 2 and 3.
String Compression
Ravi, the main problem with your approach is that, the code is not working when the string is not in sorted manner, like for eg,
Input : sskkkkkkwaerrtss
Expected output : s2k6w1a1e1r2t1s2
Your output : a1e1k6r2s4t1w1
This is happening bcz you are creating a hashmap . So its better to use the native approach in your code as,
int len=S.length();
for(int i=0;i<len;i++)
{
int count=1;
while(S[i]==S[i+1])
{
count++;
i++;
}
cout<<S[i]<<count;
}