C++, SIMPLE RECURSION, MEMOIZATION, NO MATH
Intuition\nIf we think about it carefully, the problem statement boils down to us having to generate a string of length n having at least one l, two e and one t
# Intuition\nIf we think about it carefully, the problem statement boils down to us having to generate a string of length n having at least one l, two e and one t. Any such string can be rearranged to have "leet" as it\'s substring. So we will simply maintain states within recursion that keep track of whether we have at least one l, two e\'s and one t. After the index idx reache n and marker l == 1, e == 2 and t == 1, we return 1 indicating that we have found a valid string. Else return 0 for invalid strings. Simply loop over the 26 alphabets at each index and maintain an ans variable which will be modded with 1e9 + 7 to prevent overflow. Apply simple memoization to remove exponentiality of runtime.\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\n    int dp[100000][2][3][2];\n\n    int mod = 1e9 + 7;\n\n    int solve(int idx, int l, int e, int t, int n) {\n\n        //if(n - idx < 4 && l == 0 && e == 0 && t == 0) return 0;\n\n        if(idx == n) {\n\n            if(l == 1 && e == 2 && t == 1) return 1;\n\n            return 0;\n        }\n\n        if(dp[idx][l][e][t] != -1) return dp[idx][l][e][t];\n\n        int ans = 0;\n\n        for(int i = 0; i < 26; i++) {\n\n            if(i + \'a\' == \'l\') ans = (ans + solve(idx + 1, 1, e, t, n)) % mod;\n\n            else if(i + \'a\' == \'e\') ans = (ans + solve(idx + 1, l, min(e + 1, 2), t, n)) % mod;\n\n            else if(i + \'a\' == \'t\') ans = (ans + solve(idx + 1, l, e, 1, n)) % mod;\n\n            else {\n\n                ans = (ans + solve(idx + 1, l, e, t, n)) % mod;\n            }\n        }\n\n        return dp[idx][l][e][t] = ans;\n    }\n    \n    int stringCount(int n) {\n\n        memset(dp, -1, sizeof dp);\n\n        return solve(0, 0, 0, 0, n);\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Combinatorics', 'C++']