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: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(26)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    boolean isValid(int[] freq1,int[] freq2){\n        for(int i=0;i<26;i++){\n            if(freq1[i] < freq2[i]){\n                return false;\n            }\n        }\n        return true;\n    }\n    public long validSubstringCount(String word1, String word2) {\n        int[] freq1 = new int[26];\n        int[] freq2 = new int[26];\n\n        for(char c:word2.toCharArray()){\n            freq2[c-\'a\'] += 1;\n        }\n        int j=0;\n        long ans = 0;\n        for(int i=0;i<word1.length();i++){\n            char c = word1.charAt(i);\n            freq1[c - \'a\'] += 1;\n\n            while(isValid(freq1,freq2)){\n               ans += word1.length() - i;\n               c = word1.charAt(j);\n               freq1[c - \'a\'] -= 1;\n               j+=1;\n            }\n        }\n        return ans;\n    }\n}\n```
['Hash Table', 'Sliding Window', 'Java']