String compression

My code is in the submissions and it is giving the perfect answer for all the test cases I can imagine. Please have a look at it as it is failing one of the test cases.

please share ur code in coding blocks ide