Easy CPP Solution
Complexity\n- Time complexity:\n    O(N)\n\n- Space complexity:\n    O(N)\n\n# Code\n\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    vector<long long>fac
# Complexity\n- Time complexity:\n    O(N)\n\n- Space complexity:\n    O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    vector<long long>fact;\n    long long power(long long x, long long y) {\n        long long res = 1;\n        x = x % mod;\n        while (y > 0) {\n            if (y & 1)\n                res = (res * x) % mod;\n            y = y >> 1;\n            x = (x * x) % mod;\n        }\n        return res;\n    }\n    long long solve(string word)\n    {\n        unordered_map<char,int>m;\n        for(auto s: word)\n        {\n            m[s]++;\n        }\n        long long res = 1;\n        for(auto it= m.begin();it!=m.end();it++)\n        {\n            if(it->second>1)\n            {\n                res = ((res%mod)*(fact[it->second]%mod))%mod;\n            }\n        }\n        return res%mod;\n    }\n    int countAnagrams(string s) \n    {\n        fact.resize(1e5+1,1);\n        fact[0] = 1;\n        for(int i=1;i<=1e5;i++)\n        {\n            fact[i] = ((fact[i-1]%mod)*(i%mod))%mod;\n        }\n        \n        long long tot = 1;\n        string word = "";\n        for(int i=0;i<s.length();i++)\n        {\n            if(s[i]==\' \')\n            {\n                long long res = solve(word)%mod;\n                long long ans = fact[word.length()]%mod;\n                ans = (res==1)? ans%mod: (ans * power(res,mod-2))%mod;\n                tot = ((tot%mod)*(ans%mod)%mod); \n                word = "";\n            }\n            else\n            {\n                word+=s[i];\n            }\n        }\n        long long res = solve(word)%mod;\n        long long ans = fact[word.length()]%mod;\n        ans = (res==1)? ans%mod: (ans * power(res,mod-2))%mod;\n        tot = ((tot%mod)*(ans%mod)%mod);\n\n        return tot%mod;\n    }\n};\n```
['C++']