String compression

2 test cases are failing… i think i am missing out when length is 0 and 1… can u please explain?

@chaman9
hello chaman,
cosider this case

input -> aaabbaa
ur code output will be-> a5b2a5
actual output will be -> a3b2a2

you need to compress only consecutive same character.
in above example 3 a’s are together that why it is compressed as a3
similary 2 b’s are together so it is compressed as b2
after b 2 a’s are together so it is compressed as a2
resultant string after compression will be a3b2a2

okay i realized my mistake… can you edit my code?

refer this-> https://ide.codingblocks.com/s/200885

approach ->
image

okay thanks i will try

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.