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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Run Length Encoding in Python
- Program to implement Run Length Encoding using Linked Lists
- Run Length Decoding in Linked List
- Check if an encoding represents a unique binary string
- Encoding a word into Pig Latin
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- 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
- Length of the longest substring without repeating characters
- Maximum length prefix of one string that occurs as subsequence in another
- Longest Even Length Substring such that Sum of First and Second Half is same
- Find maximum average subarray of k length
- Print string of odd length in 'X' format
- Length of the longest valid substring
- Repeated subsequence of length 2 or more
- Length of Longest sub-string that can be removed
- Convert to a string that is repetition of a substring of k length
- Check length of a string is equal to the number appended at its last
- Length of longest palindrome list in a linked list using O(1) extra space
- Count ways to increase LCS length of two strings by one
Improved By : shivanisinghss2110