![]() |
VOOZH | about |
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'.
Examples:
Input : str = 'wwwxxxwww'
Output : 'w3x3w3'
This problem has existing solution please refer Run Length Encoding link. In the simplest approach, we iterate through the string, track the current character and count its consecutive occurrences. When a different character is encountered, we append the current character and its count to the result.
Steps:
count variable to 1.Implementation:
w3x3w3
This approach uses regex to find consecutive characters and count their occurrences.
Another code:
w3x3w3