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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Run Length Encoding in Python
- Program to implement Run Length Encoding using Linked Lists
- Encoding a word into Pig Latin
- Check if an encoding represents a unique binary string
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Nth Even length Palindrome
- K-th lexicographical string of given length
- Sub-strings of length K containing same character
- Repeated subsequence of length 2 or more
- Maximum length of segments of 0's and 1's
- Length Of Last Word in a String
- Sum of first K even-length Palindrome numbers
- Check if all the palindromic sub-strings are of odd length
- Run Length Decoding in Linked List
- Count of sub-strings of length n possible from the given string
- Length of the longest substring that do not contain any palindrome
- Find max length odd parity substring
- Lexicographically smallest string of length N and sum K