Compress the String

Write a program to do basic string compression. For a character which is repeated more than once, replace consecutive duplicate occurrences with the count of repetitions e.g. if a String has 'x' repeated 5 times, replace this "xxxxx" with "x5".

Note : You don't need to print the changed string.

Sample Input:
aaabbccdsa
Sample Output:
a3b2c2dsa

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem