Sliding Window
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```java []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        int len1 = word1.length(), len2 = word2.length();\n        int[] f1 = new int[26], f2 = new int[26];\n        for (int i = 0; i < len2; ++i) ++f2[word2.charAt(i)-\'a\'];\n        int l = 0;\n        long ans = 0;\n        for (int i = 0; i < len1; ++i) {\n            ++f1[word1.charAt(i)-\'a\'];\n            while (l <= i) {\n                --f1[word1.charAt(l)-\'a\'];\n                if (check(f1, f2)) ++l;\n                else {\n                    ++f1[word1.charAt(l)-\'a\'];\n                    break;\n                }\n            }\n            if (l > 0) ans += l + 1;\n            else if (check(f1, f2)) ans += 1;\n        }\n        return ans;\n    }\n\n    private boolean check(int[] f1, int[] f2) {\n        boolean ok = true;\n        for (int j = 0; j < 26; ++j) {\n            if (f1[j] < f2[j]) {\n                ok = false;\n                break;\n            }\n        }\n        return ok;\n    }\n}\n```
['Java']