Not a good one but it's a beginner friendly brute force approach.....:)
Intuition\n1. The code leverages the concept of factorials to compute the number of distinct permutations of each word.\n\n2. It utilizes the Counter class to e
# Intuition\n1. The code leverages the concept of factorials to compute the number of distinct permutations of each word.\n\n2. It utilizes the Counter class to efficiently count the occurrences of each character in a word.\n3. By considering the multiplicities of characters and applying factorial calculations, it accurately counts the number of distinct anagrams for each word.\n4. The overall result is the product of the counts of distinct anagrams for all words in the input string s, modulo a large prime number to handle overflow.\n\n# Approach\n**Initialization:**\n>The code initializes a variable MOD to store the modulo value, which is set to 10^9 + 7.\nIt then splits the input string s into words and stores the unique words in a set called words.\n\n**Loop through Words:**\n>It iterates over each unique word in the set of words extracted from the input string.\nFor each word, it constructs a Counter object to count the occurrences of each character in the word.\n\n**Calculate Product of Factorials:**\n\n>For each word, it calculates the factorial of the length of the word using math.factorial(len(word)) and multiplies it with the product variable.\nAdditionally, for each character count in the Counter object, it divides the product by the factorial of that count.\nThis process effectively counts the number of distinct permutations of each word, considering the multiplicities of each character.\n\n**Return Result:**\n>Finally, it returns the product modulo MOD, which represents the count of distinct anagrams of the input string s.\n\n# Complexity\n- Time complexity:\n O(n * m)\nn is the number of words in the input string\nm is the maximum length of any word.\n\n- Space complexity:\n O(n + m)\nn is the number of words in the input string\nm is the maximum number of unique characters in any word.\n\n# Code\n```\nfrom collections import Counter\nclass Solution:\n    def countAnagrams(self, s: str) -> int:\n        MOD = 10**9 + 7\n        words = set(s.split())\n        product = 1\n        for word in words:\n            count = Counter(word)\n            product = product * math.factorial(len(word))\n            for i in count.values():\n                if i == 1 or i == 2:\n                    product = product // i\n                else:\n                    product = product // math.factorial(i)\n        return product % MOD\n```
['Hash Table', 'Math', 'String', 'C', 'Combinatorics', 'Counting', 'Python', 'C++', 'Java', 'Python3']