String compression

in my code … output is coming in alphabetically order … I think that is the reason why I am getting 2 test cases wrong… how to get the alphabets output in the same order as they are entered by the user

hi @dhirenkinha;
in this follow basic approach.
make 2 steings s,ans="".
input s;
let s=d3b2a4.
iterate s and make char c=s[i] and int d=s[i+1].
now add d times c in ans string.
Hope dis helps.

I think you read the question completely opposite … we are supposed to print the compressed form … not the expanded form

@dhirenkinha
for compressing the string, u can use d following approach:
int k=0
for i from 0 to n-2
if(string[i]==string[i+1]){
k+=1;
}
else{
k++;
cout<<a[i]<<k;
k=0;
}
eg. input=aaccbbb
first it will print a2 , then c2 then b3.
Hope dis helps :slight_smile: .