O(logn) solution beats 100%
IntuitionUse the Inclusion-Exclusion Principle to calculate the number of strings that cannot form "leet" as a substring after rearrangement. Subtract this coun
# Intuition
Use the Inclusion-Exclusion Principle to calculate the number of strings that cannot form "leet" as a substring after rearrangement. Subtract this count from \(26^n\) (total possible strings) to get the final answer.


# Complexity
- Time complexity: O(logn)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    const long long MOD = 1e9 + 7;

    long long modExp(long long base, long long exp) {
        long long result = 1;
        while (exp > 0) {
            if (exp % 2 == 1) {
                result = (result * base) % MOD;
            }
            base = (base * base) % MOD;
            exp /= 2;
        }
        return result;
    }

    int stringCount(int n) {
        long long term_26 = modExp(26, n);
        long long term_25 = modExp(25, n);
        long long term_24 = modExp(24, n);
        long long term_23 = modExp(23, n);

        long long result = (term_26
                         - 3 * term_25 % MOD
                         + 3 * term_24 % MOD
                         - term_23
                         - n * modExp(25, n - 1) % MOD
                         - n * modExp(23, n - 1) % MOD
                         + 2 * n * modExp(24, n - 1) % MOD) % MOD;

        // Ensure result is non-negative
        if (result < 0) {
            result += MOD;
        }

        return result;
    }
};

```
['Combinatorics', 'C++']