Unexpected output

Input: acb
Expected output: a2c-1b
My output: a2cb
why is my code unable to generate the -1 difference?

My solution: https://ide.codingblocks.com/s/405943

Question: https://online.codingblocks.com/app/player/178555/content/173728/4823/code-challenge

@mohaktrivedi your condition in the for loop is confusing:
thats why it is not calculating for the last characters and resulting in the wrong answer.
see this code:


if you have any doubt you can ask here:
Happy Learning!!

@tusharaggarwal272 Thanks! Instead of focusing on printing the required output, I was focusing on how to store it and then print it. Your solution is easy to understand.

@mohaktrivedi you can mark this as resolved.