Not a Hard Problem || Easy C++ Solution using (inverse modulo and binary exponentiation)
\n\n# Approach\n\nConsider each space seperated string as chunk of that string, find number of permutaion of each chunk and multiply them. \n\nfor finding numbe
\n\n# Approach\n\nConsider each space seperated string as chunk of that string, find number of permutaion of each chunk and multiply them. \n\nfor finding number of ways you should we aware of basic formula like : \nto arrange k different things number of ways \n= (k1 + k2 + k3) ! / (k1! * k2! * k3!) , where ki\'s are number of things in ith portion. \n\nhere to find modulo inverse for range see code snippet and if you don\'t get it -->  just dry run it. :)) \n\n\n\n# Code\n```\nclass Solution {\npublic:\n\n    long long pow1(long long a , long long n , int md){\n\n        if(n == 0) return 1; \n\n        long long x  = pow1(a , n/2 , md) % md; \n\n        if(n % 2 == 0){\n            return (x % md * x % md ) % md; \n        }\n        return (x % md * x % md * a) % md; \n    }\n\n    int countAnagrams(string s) {\n\n        \n        int n = s.size(); \n        vector < long long > fact(n+1);\n\n        fact[0] = 1; \n        fact[1] = 1; \n\n        int md = 1e9 + 7; \n        for(int i = 2 ; i <= n ; i++){\n            fact[i] = (fact[i-1] % md * i % md) % md; \n        }\n\n        long long forward = pow1(fact[n] , md - 2 , md) % md; \n\n        vector < long long > invfact(n+1); \n        invfact[n] = forward; \n\n        for(int i = n-1 ; i > 0 ; i--){\n\n            invfact[i] = (invfact[i+1] % md * (i+1) % md) % md; \n        }\n\n        long long ans = 1; \n\n        map < char , int > mp; \n\n        int curr = 0; \n\n        for(int i = 0 ; i <=n ; i++){\n   \n            if(i == n || s[i] == \' \'){\n\n                ans = (ans % md * fact[curr] % md) % md; \n\n                for(auto & p : mp){\n                    ans = (ans % md * invfact[p.second] % md) % md; \n                }\n\n                mp.clear();\n\n                curr = 0;  \n            }\n            else{\n                mp[s[i]]++; \n                curr++; \n            }     \n        }\n\n        return ans % md;    \n    }\n};\n```\n\n![image.png](https://assets.leetcode.com/users/images/05c873bd-8d7b-417c-82c1-85bed27e7787_1709559687.058089.png)\n
['C++']