Compress the String

Difficulty: MEDIUM
Avg. time to solve
25 min
Success Rate

Problem Statement
Suggest Edit

Write a program to do basic string compression. For a character which is consecutively repeated more than once, replace consecutive duplicate occurrences with the count of repetitions.

If a string has 'x' repeated 5 times, replace this "xxxxx" with "x5".
The string is compressed only when the repeated character count is more than 1.
Note :
Consecutive count of every character in the input string is less than or equal to 9.
Input Format:
The first and only line of input contains a string without any leading and trailing spaces.
Output Format:
The only line of output prints the updated string.
You are not required to print anything. It has already been taken care of, just implement the function.
1 <= N <= 10^6
Where N is the length of the input string.

Time Limit: 1 second
Sample Input 1:
Sample Output 1:
Sample Input 2:
Sample Output 2:
Want to solve this problem? Login now to get access to solve the problems