Failing testcase 2 and testcase 3

PLEASE FIND WHERE IS THE PROBLEM IN THE CODE

https://ide.codingblocks.com/s/72057

@shashank.21sep hey shashank your output is not write for this case
annnnhhhhxxx
your output is
a1h4n4x3
but it should be like
a1n4h4x3
your code is producing output in sorted order

I would suggest you implement simple approach
for i to length of the string
take a variable count=1;
apply a while loop
while(str[i]==str[i+1]&&i<len-1)
i++;
count++;
in nested loop of i
cout<<string[i]<<count;