Python 3 || 11 lines, w/ explanation || T/S: 96 % / 99%
The problem reduces to finding the multinomial coefficient for each word and then returning their product as the answer. (The binomial coeficient is a particula
- The problem reduces to finding the *multinomial coefficient* for each word and then returning their product as the answer. (The *binomial coeficient* is a particular case of the multinomial coefficient.)\n\n- Unfortunately, computing each of these multinomial coefficients, because by definition they require factorial computations, cost significant time and space.\n- Fortunately, binomial coefficients can be computed very efficiently (*O*(*n*) by a recurrence relation, which is used in the `math.comb` method.\n- And more fortunately, there\'s another recurrence relation that permits multinomial coefficients to be computed much more efficiently from binomial coeficients. \n\n(The interested reader may wish to do the research on these mathematical references.)\n___\nHere\'s the code:\n```\nclass Solution:\n    def countAnagrams(self, s: str, ans = 1) -> int:\n\n        prod = lambda x, y: x*y %1_000_000_007\n\n        def count(vals):\n            res, sm = 1, sum(vals)\n            for r in vals:\n                res = prod(res, comb(sm,r))\n                sm -= r\n            return res\n\n       \n        for word in s.split():\n            vals = Counter(word).values()\n            ans = prod(ans, count(vals))\n\n        return ans\n\n```\n[https://leetcode.com/problems/count-anagrams/submissions/1290637367/](https://leetcode.com/problems/count-anagrams/submissions/1290637367/)\n\n\nI could be wrong, but I think that time is *O*(*MN*) and space is *O*(*M*), in which, *N* ~ `len(s)` and *M* ~ *maxLength*(*words*)
['Python3']