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```\nimport java.util.*;\n\n\nclass Solution {\n\n    int M = (int) 1e9 + 7;\n\n\n    // for each word: find perms and multiply for all words\n    // Permutations of size N = N!  = N! / 1! * 1! .. 1!\n    // BUT with DUPLICATES INSIDE need to divide by the factorial! of each duplicate count:\n    // aaabb\n    // N!/(d1! * d2!) = 5!/3!*2! = 4*5/2 = 10\n\n    // 3!/2! = 3\n    // 3!    = 6\n    //        18\n    public int countAnagrams(String s) {\n        inverse[1] = 1;   // map x -> 1 / x == x^(-1)\n        for (int i = 2; i <= 100000; i++) {\n            inverse[i] = (M - M / i) * inverse[M % i] % M;\n        }\n\n        long total = 1;\n        String[] words = s.split(" ");\n        for (String w : words) {\n            int[] cnts = new int[26];\n            int n = w.length();\n\n            long perms = fact(n);\n            for (int i = 0; i < n; i++) cnts[w.charAt(i) - \'a\']++;\n            for (int cnt : cnts) {\n                if (cnt == 0) continue;\n                perms = (perms * inverseFact(cnt)) % M;\n            }\n            total = (total * perms) % M;\n        }\n        return (int) (total % M);\n    }\n\n\n    long[] inverse = new long[100005];\n    long[] inverseFact = new long[100005];\n    long[] fact = new long[100001];\n\n    long fact(int n) {\n        if (n < 3) return n;\n        if (fact[n] != 0) return fact[n];\n        return fact[n] = (n * fact(n - 1)) % M;\n    }\n\n    long inverseFact(int n) { // perform factorial! going down on numbers using their INVERSES!!!\n        if (n == 1) return 1;\n        if (inverseFact[n] != 0) return inverseFact[n];\n        return inverseFact[n] = (inverse[n] * inverseFact(n - 1)) % M;\n    }\n\n}\n\n```
['Java']