String compression(string challenges)

ques: https://hack.codingblocks.com/contests/c/537/107
code: https://ide.codingblocks.com/s/53072
can not pass test case 2,3. What conditions my code is missing?

Hey, your approach is not correct, it will not work for all the cases. check for this case
input:
aaabbccbbds

your code’s output:
a3b4b4

but the expected output is:
a3b2c2b2d1s1

hi I have changed my code but now test case 4 is failing.
https://ide.codingblocks.com/s/53072

Hey Siddharth, still your code is not working for the case when length of the string is 1. for eg.
input:
a
your code’s output :
a

but the expected output is:
a1

1 Like