if char_frequency_for_letter [ = del char_frequency_for_letter [cif not char_frequency_for_letter all characters for letter_text are matched return true empty char_frequency_for_letter means every char in letter_text can be covered by character in magazine_text return not char_frequency_for_letter pythonic solution that exploits collections counter note that the subtraction only keeps keys with positive counts def is_letter_constructible_from_magazine_pythonic letter_text magazine_text )return (not collections counter letter_text collections counter magazine_text )in the worst-casethe letter is not constructible or the last character of the magazine is essentially required thereforethe time complexity is ( nwhere and are the number of characters in the letter and magazinerespectively the space complexity is the size of the hash table constructed in the pass over the letteri ( )where is the number of distinct characters appearing in the letter if the characters are coded in asciiwe could do away with the hash table and use entry integer array awith [ibeing set to the number of times the character appears in the letter