0

Simple Run Length Encoding.

Problem statement :

if the input string is “wwwwaaadexxxxxx”, then the function should return “w4a3de1x6″

Basically Run Length Encoding.

Easiest way to do this is using a Dictionary data structure.

You travel through the string once (O(n)) and fill the dictionary as following :

Key : Char Value: Count,

so w:4, a:3, d:1, e:1, x:6.

After filling the dictionary, you can just travel through the dictionary and concat key+value to print run length encoded string.

To preserve the order you can also use LinkedHashSet<> data structure.

here is the code using Dictionary.

 

 

 


Warning: count(): Parameter must be an array or an object that implements Countable in /home/algotu5/public_html/wp-includes/class-wp-comment-query.php on line 405