Given an input string, write a function that returns the Run Length Encoded string for the input string.
For example, if the input string is “wwwwaaadexxxxxx”, then the function should return “w4a3d1e1x6”.
a) Pick the first character from source string.
b) Append the picked character to the destination string.
c) Count the number of subsequent occurrences of the picked character and append the count to destination string.
d) Pick the next character and repeat steps b) c) and d) if end of string is NOT reached.
Time Complexity: O(n)
Please write comments if you find the above code/algorithm incorrect, or find better ways to solve the same problem.
- Run Length Encoding in Python
- Decode a string recursively encoded as count followed by substring
- Count substrings with same first and last characters
- Rearrange a string so that all same characters become d distance away
- Write your own atoi()
- An in-place algorithm for String Transformation
- Lexicographic rank of a string
- Print all interleavings of given two strings
- Print all permutations with repetition of characters
- Find the smallest window in a string containing all characters of another string
- Reverse words in a given string
- Print list items containing all characters of a given word
- Given a string, find its first non-repeating character
- Write a program to print all permutations of a given string
- Remove duplicates from a given string