Hash Tables: Ransom Note

  • + 0 comments
    def checkMagazine(magazine, note):
        # Write your code here
        
        word_count = {}
        flag = 'Yes'
        
        for i in magazine:
            if i in word_count:
                word_count[i] += 1
            else:
                word_count[i] = 1
        
        for i in note:
            if i in word_count and word_count[i] > 0:
                word_count[i] -= 1
            else:
                flag = 'No'
            
        print(flag)