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.
The consecutive count of every character in the input string is less than or equal to 9.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains one string ‘S’ denoting the input string that needs to be compressed.
For each case, we need to print a string representing the compressed string.
The output of each test case will be printed in a separate line.
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= |S| <= 5000
Where |S| is the size of the string.
Time Limit: 1 sec
Here, we can simply traverse the string and run two loops where the outer loop will hold the unique characters and the inner loop will count the consecutive repetitions of that character. Once, we encounter a new character, our inner loop breaks and now our outer loop will start again from the new character. In this process, while getting the repetitions of each character, we can append the character and its count of repetitions depending on the condition that the repetition should be greater than 1.
Equal Arrays
1-3 Palindrome
Ninja And The Strictly Increasing Array
Maximize
Search Pattern (KMP - Algorithm)
Search Pattern (KMP - Algorithm)
Search Pattern (KMP - Algorithm)