C++, sliding window, O(1)/O(n)
Code
# Code
```cpp []
class Solution {
public:
    long long validSubstringCount(string word1, string word2) {
        long long total = 0;

        array<int, 26> target = {0};
        for (size_t i = 0; i < word2.size(); ++i) {
            ++target[word2[i] - 'a'];
        }

        size_t l = 0;
        for (size_t r = 0; r < word1.size(); ++r) {
            --target[word1[r]-'a'];

            while (isAcceptable(target)) {
                total += static_cast<long long>(word1.size() - r);
                ++target[word1[l]-'a'];
                ++l;
            }
        }
        return total;
    }

    bool isAcceptable(const array<int, 26>& arr) {
        for (size_t i = 0; i < 26; ++i) {
            if (arr[i] > 0) {
                return false;
            }
        }
        return true;
    }
};
```
['C++']