Simple approach using the basics of maths
Intuition\n Describe your first thoughts on how to solve this problem. \nJust start thinking about the anagram so we get an idea that the total number of anagra
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust start thinking about the anagram so we get an idea that the total number of anagram for a word is the total number of permutation of this word.\nAnd second thing is that the total number of anagram is equal to the product of the permutations of the each word.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMake a map use to keeep the count of the each character of one word.\nSo that we can calculate the permutation of the word.\nThen iterate over the loop-\nif get s[i]==\' \' that means a word end so calculate the number of permutation for this word and \nans*=f(m) f use to calculate the permutation using m map\nand m.clear() to clear the map\nelse m[s[i]]++ as to count the number of char\n\nat the end of loop there must be one last word remains that why \nans+=f(m);\n\nat last \nreturn ans;\n\n\n\n# Complexity\n- Important concept: To calulate the permutation we use formula:\n-        P=(total cnt of char in word)! /((cnt of each char c1)! * (c2)! * ...)\n- To calculate the a/b%mod m:\n-        a/b%mod m=(a mod m) *(b power -1 mod m)=(a mod m) *(b power(m-2) mod m)\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(26)\n\n# Code\n```\nclass Solution {\npublic:\n     int mod=1e9+7;\n     int myPow(int x, int n) {\n         long long x1=x;\n         long long ans=1;\n         while(n>0){\n             if(n%2!=0){\n                 ans=(ans*x1)%mod;\n             }\n            x1=(x1*x1)%mod;\n            n=n/2;\n             \n         }\n         return ans%mod;\n    }\n    long long fact(int n){\n        if(n==0 || n==1){\n            return 1;\n        }\n        long long ans=1;\n        for(int i=2;i<=n;i++){\n            ans=(ans*i)%mod;\n        }\n        return ans%mod;\n    }\n    long long f(unordered_map<char,int>&m){\n       int cnt=0;\n       long long b=1;\n       for(auto i:m){\n           cnt+=i.second;\n           b=(b%mod*fact(i.second)%mod)%mod;\n       }\n       long long a=fact(cnt);\n       long long c=myPow(b,mod-2)%mod;\n       return (a*c)%mod;\n\n    }\n    int countAnagrams(string s) {\n        int n=s.size();\n        unordered_map<char,int>m;\n        long long ans=1;\n        for(int i=0;i<n;i++){\n            if(s[i]==\' \'){\n                ans=((ans%mod)*(f(m)%mod))%mod;\n                m.clear();\n            }\n            else{\n                m[s[i]]++;\n            }\n        }\n        ans=((ans%mod)*(f(m)%mod))%mod;\n        return ans%mod;\n    }\n};\n```
['C++']