✅☑[C++/Java/Python/JavaScript] || Beats 100% || EXPLAINED🔥
PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n(Also explained in the code)\n1. Dynamic Programming Array (ans):\n\n    - ans[i][j][k][l] represents the n
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n1. **Dynamic Programming Array (ans):**\n\n    - `ans[i][j][k][l]` represents the number of strings of length `i` with `j` occurrences of `l`, `k` occurrences of `e`, and `l` occurrences of `t`.\n1. **Base Case:**\n\n    - Initialize the base case where there is one string of length 0 with no `l`, `e`, and `t`.\n1. **Dynamic Programming Transition Rules:**\n\n    - Use dynamic programming to fill the ans array based on the transition rules.\n    - Transition rules consider the current state (`j`, `k`, `l`) and update the count for the next length.\n1. **Result:**\n\n- The result is the count of strings of length `n` with one `l`, two `e`, and one \'t\' (`ans[n][1][2][1]`).\n\n\n\n# Complexity\n- *Time complexity:*\n   $$O(n)$$\n    \n\n- *Space complexity:*\n   $$O(n)$$\n    \n\n\n# Code\n```C++ []\nusing ll = long long;\nconst ll mod = 1e9 + 7;\nll ans[100001][2][3][2];\n\n// Function to add two numbers and take the result modulo \'mod\'\nvoid cadd(ll& x, ll y) {\n    x = (x + y) % mod;\n}\n\nclass Solution {\npublic:\n    // Function to count the number of strings of length n\n    int stringCount(int n) {\n        // Initialize the 4D array \'ans\' with zeros\n        for (int i = 0; i <= n; i++)\n            for (int j = 0; j < 2; j++)\n                for (int k = 0; k < 3; k++)\n                    for (int l = 0; l < 2; l++)\n                        ans[i][j][k][l] = 0;\n\n        // Base case: there is one string of length 0 with no \'l\', \'e\', \'t\'\n        ans[0][0][0][0] = 1;\n\n        // Dynamic Programming to fill the \'ans\' array\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < 2; j++)\n                for (int k = 0; k < 3; k++)\n                    for (int l = 0; l < 2; l++) {\n                        // Transition rules based on the current state\n                        cadd(ans[i + 1][j][k][l], ans[i][j][k][l] * 23);\n                        cadd(ans[i + 1][min(1, j + 1)][k][l], ans[i][j][k][l]);\n                        cadd(ans[i + 1][j][k][min(1, l + 1)], ans[i][j][k][l]);\n                        cadd(ans[i + 1][j][min(2, k + 1)][l], ans[i][j][k][l]);\n                    }\n\n        // The result is the count of strings of length n with one \'l\', two \'e\', and one \'t\'\n        return (int)(ans[n][1][2][1]);\n    }\n};\n\n\n```\n\n```C []\n\ntypedef long long ll;\n\nconst ll mod = 1000000007;\nll ans[100001][2][3][2];\n\n// Function to add two numbers and take the result modulo \'mod\'\nvoid cadd(ll* x, ll y) {\n    *x = (*x + y) % mod;\n}\n\n// Function to count the number of strings of length n\nint stringCount(int n) {\n    // Initialize the 4D array \'ans\' with zeros\n    for (int i = 0; i <= n; i++)\n        for (int j = 0; j < 2; j++)\n            for (int k = 0; k < 3; k++)\n                for (int l = 0; l < 2; l++)\n                    ans[i][j][k][l] = 0;\n\n    // Base case: there is one string of length 0 with no \'l\', \'e\', \'t\'\n    ans[0][0][0][0] = 1;\n\n    // Dynamic Programming to fill the \'ans\' array\n    for (int i = 0; i < n; i++)\n        for (int j = 0; j < 2; j++)\n            for (int k = 0; k < 3; k++)\n                for (int l = 0; l < 2; l++) {\n                    // Transition rules based on the current state\n                    cadd(&ans[i + 1][j][k][l], ans[i][j][k][l] * 23);\n                    cadd(&ans[i + 1][j < 1 ? j + 1 : 1][k][l], ans[i][j][k][l]);\n                    cadd(&ans[i + 1][j][k][l < 1 ? l + 1 : 1], ans[i][j][k][l]);\n                    cadd(&ans[i + 1][j][k < 2 ? k + 1 : 2][l], ans[i][j][k][l]);\n                }\n\n    // The result is the count of strings of length n with one \'l\', two \'e\', and one \'t\'\n    return (int)(ans[n][1][2][1]);\n}\n\n\n```\n```Java []\npublic class Solution {\n    // Function to count the number of strings of length n\n    public int stringCount(int n) {\n        long[][][][] ans = new long[100001][2][3][2];\n        final long mod = 1000000007;\n\n        // Function to add two numbers and take the result modulo \'mod\'\n        java.util.function.BiFunction<Long, Long, Long> cadd = (x, y) -> (x + y) % mod;\n\n        // Initialize the 4D array \'ans\' with zeros\n        for (int i = 0; i <= n; i++)\n            for (int j = 0; j < 2; j++)\n                for (int k = 0; k < 3; k++)\n                    for (int l = 0; l < 2; l++)\n                        ans[i][j][k][l] = 0;\n\n        // Base case: there is one string of length 0 with no \'l\', \'e\', \'t\'\n        ans[0][0][0][0] = 1;\n\n        // Dynamic Programming to fill the \'ans\' array\n        for (int i = 0; i < n; i++)\n            for (int j = 0; j < 2; j++)\n                for (int k = 0; k < 3; k++)\n                    for (int l = 0; l < 2; l++) {\n                        // Transition rules based on the current state\n                        ans[i + 1][j][k][l] = cadd.apply(ans[i + 1][j][k][l], ans[i][j][k][l] * 23);\n                        ans[i + 1][Math.min(1, j + 1)][k][l] = cadd.apply(ans[i + 1][Math.min(1, j + 1)][k][l], ans[i][j][k][l]);\n                        ans[i + 1][j][k][Math.min(1, l + 1)] = cadd.apply(ans[i + 1][j][k][Math.min(1, l + 1)], ans[i][j][k][l]);\n                        ans[i + 1][j][Math.min(2, k + 1)][l] = cadd.apply(ans[i + 1][j][Math.min(2, k + 1)][l], ans[i][j][k][l]);\n                    }\n\n        // The result is the count of strings of length n with one \'l\', two \'e\', and one \'t\'\n        return (int)(ans[n][1][2][1]);\n    }\n}\n\n\n```\n\n```python3 []\nclass Solution:\n    # Function to count the number of strings of length n\n    def stringCount(self, n):\n        ans = [[[ [0 for _ in range(2)] for _ in range(3)] for _ in range(2)] for _ in range(100001)]\n        mod = 10**9 + 7\n\n        # Function to add two numbers and take the result modulo \'mod\'\n        def cadd(x, y):\n            return (x + y) % mod\n\n        # Initialize the 4D array \'ans\' with zeros\n        for i in range(n + 1):\n            for j in range(2):\n                for k in range(3):\n                    for l in range(2):\n                        ans[i][j][k][l] = 0\n\n        # Base case: there is one string of length 0 with no \'l\', \'e\', \'t\'\n        ans[0][0][0][0] = 1\n\n        # Dynamic Programming to fill the \'ans\' array\n        for i in range(n):\n            for j in range(2):\n                for k in range(3):\n                    for l in range(2):\n                        # Transition rules based on the current state\n                        ans[i + 1][j][k][l] = cadd(ans[i + 1][j][k][l], ans[i][j][k][l] * 23)\n                        ans[i + 1][min(1, j + 1)][k][l] = cadd(ans[i + 1][min(1, j + 1)][k][l], ans[i][j][k][l])\n                        ans[i + 1][j][k][min(1, l + 1)] = cadd(ans[i + 1][j][k][min(1, l + 1)], ans[i][j][k][l])\n                        ans[i + 1][j][min(2, k + 1)][l] = cadd(ans[i + 1][j][min(2, k + 1)][l], ans[i][j][k][l])\n\n        # The result is the count of strings of length n with one \'l\', two \'e\', and one \'t\'\n        return int(ans[n][1][2\n\n\n\n```\n```javascript []\nclass Solution {\n    // Function to add two numbers and take the result modulo \'mod\'\n    cadd(x, y) {\n        return (x + y) % (1e9 + 7);\n    }\n\n    // Function to count the number of strings of length n\n    stringCount(n) {\n        // Initialize the 4D array \'ans\' with zeros\n        const ans = new Array(n + 1)\n            .fill(null)\n            .map(() =>\n                new Array(2)\n                    .fill(null)\n                    .map(() =>\n                        new Array(3)\n                            .fill(null)\n                            .map(() => new Array(2).fill(0))\n                    )\n            );\n\n        // Base case: there is one string of length 0 with no \'l\', \'e\', \'t\'\n        ans[0][0][0][0] = 1;\n\n        // Dynamic Programming to fill the \'ans\' array\n        for (let i = 0; i < n; i++) {\n            for (let j = 0; j < 2; j++) {\n                for (let k = 0; k < 3; k++) {\n                    for (let l = 0; l < 2; l++) {\n                        // Transition rules based on the current state\n                        ans[i + 1][j][k][l] = this.cadd(\n                            ans[i + 1][j][k][l],\n                            ans[i][j][k][l] * 23\n                        );\n                        ans[i + 1][Math.min(1, j + 1)][k][l] = this.cadd(\n                            ans[i + 1][Math.min(1, j + 1)][k][l],\n                            ans[i][j][k][l]\n                        );\n                        ans[i + 1][j][k][Math.min(1, l + 1)] = this.cadd(\n                            ans[i + 1][j][k][Math.min(1, l + 1)],\n                            ans[i][j][k][l]\n                        );\n                        ans[i + 1][j][Math.min(2, k + 1)][l] = this.cadd(\n                            ans[i + 1][j][Math.min(2, k + 1)][l],\n                            ans[i][j][k][l]\n                        );\n                    }\n                }\n            }\n        }\n\n        // The result is the count of strings of length n with one \'l\', two \'e\', and one \'t\'\n        return ans[n][1][2][1];\n    }\n}\n\n```\n\n\n---\n\n\n\n# PLEASE UPVOTE IF IT HELPED\n\n---\n---\n\n\n---
['Dynamic Programming', 'C', 'C++', 'Java', 'Python3', 'JavaScript']