Solutions for Run Length
View the challenge

This challenge requires you to calculate the run length encoding of a string. This compresses the string in the following way: wherever there are multiple repeating characters in a string, replace them with the character count along with the original character. For example: the string "aaabbc" results in an encoding of "3a2b1c" You can see that the count comes first followed by the character. The following code will loop through the string checking whether the next character in the sequence is the same as the previous character, if so, add 1 to its count. Once we reach a different character, append the previous count + the character to a final compressed string that we will return in the end.

You need to be a member to see the rest of this solution and code.