Easy Permutation Approach - Beats 91% ✅
Intuition 🤔Calculate anagram counts using the permutation formula. Compute the factorial of total letters, divide by the product of factorials of repeating lett
# Intuition 🤔  
Calculate anagram counts using the permutation formula. Compute the factorial of total letters, divide by the product of factorials of repeating letters, and multiply results for each word in the string.  

# Approach 🚀  
1. Compute the factorial of the total number of letters.  
2. Compute the factorial of each letter’s frequency and take the modular inverse to handle divisions.  
3. Calculate permutations for each word separately and multiply the results.  
4. Use modular arithmetic to prevent overflow.  

# Complexity ⏳  
- **Worst-case Time Complexity:** \(O(n + m \log m)\)  
- **Average-case Time Complexity:** \(O(n)\)  
- **Space Complexity:** \(O(1)\)  

# Code 💻  
```cpp
class Solution {
public:
    const int mod = 1e9 + 7;

    int fact(int n){
        int ans = 1;
        for(int i = 2; i <= n; i++){
            ans = (1LL * ans * i) % mod;
        }

        return ans;
    }

    int modularInverse(int b){
        int ans = 1, m = mod - 2;
        while(m){
            if(m & 1)ans = (1LL * ans * b) % mod;
            b = (1LL * b * b) % mod;
            m >>= 1;
        }

        return ans;
    }

    int permutations(int& size, vector<int>& count){
        int sizeFact = fact(size);
        int denomFact = 1;
        for(auto i : count){
            if(i > 1){
                int temp = fact(i);
                denomFact = (1LL * denomFact * temp) % mod;
            }
        }

        return (1LL * sizeFact * modularInverse(denomFact)) % mod;
    }

    int countAnagrams(string s) {
        vector<int> count(26);
        int ans = 1;
        int size = 0;

        for(auto ch : s){
            if(ch == ' '){
                int temp = permutations(size, count);
                ans = (1LL * ans * temp) % mod;
                count = vector<int>(26);
                size = 0;
            }
            else{
                count[ch - 'a']++;
                size++;
            }
        }

        int temp = permutations(size, count);
        ans = (1LL * ans * temp) % mod;


        return ans;
    }
};
```
['C++']