Math Approach Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nIt\'s a simple math approach.\n# Approach\n Describe your approach to solving the probl
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt\'s a simple math approach.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nConsider 4 conditions: \n    (a) there is no \'l\' in string.\n    (b) there is no \'t\' in string.\n    (c) there is no \'e\' in string.\n    (d) there is exactly one \'e\' in string.\n\nHence, the number of solution is:\nAll possible - (1 condition satisfy) + (2 conditions satisfy) - (3 conditions satisfy) + (4 conditions satisfy)\n# Complexity\n- Time complexity:$O(n)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$O(1)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    static const long long MOD = 1e9 + 7;\n    long long pow(long long n, int k)\n    {\n        long long a = 1;\n        while (k)\n        {\n            a = (a * n) % MOD;\n            k--;\n        }\n        return a;\n    }\n    int stringCount(int n_) {\n        long long ans = 0;\n        long long n = n_;\n        ans = ans + pow(26, n); // all possible of length n\n        ans = ans - pow(25, n) * 3; //no \'l\' or no \'t\' or no \'e\'\n        ans = ans - pow(25, n - 1) * n; // exactly one \'e\'\n        ans = ans + pow(24, n) * 3; // (no \'l\' and no \'t\') or (no \'t\' and no \'e\') or (no \'l\' and no \'e\')\n        ans = ans + pow(24, n - 1) * n * 2; //(no \'l\' or no \'t\') and one \'e\'\n        ans = ans - pow(23, n); //no \'l\' and no \'t\' and no \'e\'\n        ans = ans - pow(23, n - 1) * n;//no \'l\' and no \'t\' and one \'e\'\n        ans %= MOD;\n        if (ans < 0)\n            ans += MOD;\n        return ans;\n    }\n};\n```
['Math', 'C++']