🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 78 - 100% Working Solution | Buy Now
Description
2 Live
String Encoding
Encode a given string by collapsing consecutive instances of a single character into two pieces of information: the number of instances and the character. Note that even single characters should be run-length encoded. If the string is empty, return an empty string. Your implementation should work on all alphanumeric characters.
Function Description
Complete the function collapselnput which takes a string input as a parameter and returns the compressed string.
Sample Input:
GGGGGrrrrrrrrrrrrttt
Sample Output:
5G14r3t
Explanation:
There are 5 'G' characters, then there are 14 'r's, then there is 1 't'.