Given a string of alphabets (from a to z), Print the count of the character appearing in the string right next to it. This is also called Run Length Encoding.
str = "aabbcccddddeeeee"
str = "2a2b3c4d5e"
Every character appearing in the string will have the count printed right next to it. In the above example, a
appeared 2
times, b
appeared 3
times and so on.
str = "azvdaaarrtaaa"
str = "7a1z1v1d2r1t"
Same approach as before, All the count of a specific character are printed before the string character. Note that even if the character is repeated after an interval of unique characters, they'll be printed at the place where they first occured.
Click to reveal
Can you try using a hash map / Object /map to keep the count of the characters?
Click to reveal
A good idea will be to store the characters first and then iterate over them to print their frequencies.