having a string "aaabbcdddaabbe" count how many times each letter appears.
Sigiloso
Here's a simple solution using a dictionary in python Let n be the number of letters in string, the time complexity of this algorithm is O(n) because we must iterate through each letter in the given input string. Dictionary insertion and retrieval is O(1). def countLetters(string): count_dictionary = {} # initialize the count dictionary for letter in string: count_dictionary[letter] = 0 # get the count of each letter for letter in string: count_dictionary[letter] += 1 print(count_dictionary)