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 or String Compression.
map
object that will store all the counts of variables.not
add it to the map and initialize it to 1
. Otherwise, increment the count.map
object (called hash map), Print the count
along with the key
of the hash map.O(n)
- Since we are iterating the array twice but separately.