# Easy and Simple Approach using Factorial And modular inverse
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    const int MOD = 1e9 + 7; // Choose your modulo according to constraints\n    long long fact(long long n){\n        if(n==0 || n==1){\n            return 1;\n        }\n        long long an=1;\n        for(long long i=1;i<=n;i++){\n            an=(an*i) % MOD; // Perform modulo operation here\n        }\n        return an;\n    }\n    long long countAnagrams(string s) {\n        long long n=s.size();\n        vector<pair<int,map<char,long long>>> v;\n        map<char,long long> m;\n        int j=0;\n        for(long long i=0;i<n;i++){\n            if(s[i]!=\' \'){\n                m[s[i]]++;\n            }else{\n                v.push_back({i-j,m});\n                j=i+1;\n                m.clear();\n            }\n        }\n        if(m.size()>0){\n            v.push_back({n-j,m});\n        }\n        long long ans=1;\n        for(long long i=0;i<v.size();i++){\n            long long sz=v[i].first;\n            long long res=fact(sz);\n            for(auto it:v[i].second){\n                res=(res * modularInverse(fact(it.second))) % MOD; // Modular inverse used here\n            }\n            ans=(ans*res) % MOD; // Perform modulo operation here\n        }\n        return ans;\n    }\n    \n    // Function to calculate modular inverse using Extended Euclidean Algorithm\n    long long modularInverse(long long a) {\n        long long b = MOD, u = 1, v = 0;\n        while (b) {\n            long long t = a / b;\n            a -= t * b; swap(a, b);\n            u -= t * v; swap(u, v);\n        }\n        u %= MOD;\n        if (u < 0) u += MOD;\n        return u;\n    }\n};\n```
['Ordered Map', 'C++']