Arrays || JAVA
Code\njava []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        int[] freq2 = freqCounter(word2); \n        long tot
# Code\n```java []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        int[] freq2 = freqCounter(word2); \n        long totalValid = 0;\n        int left = 0;\n        int[] currfreq = new int[26]; \n\n        for (int right = 0; right < word1.length(); right++) {\n            char cr = word1.charAt(right);\n            currfreq[cr - \'a\']++; \n\n            while (freqChecker(currfreq, freq2)) {\n                totalValid += word1.length() - right;  \n                currfreq[word1.charAt(left) - \'a\']--; \n                left++;\n            }\n        }\n        return totalValid;\n    }\n\n    private int[] freqCounter(String s) {\n        int[] freq = new int[26];\n        for (char ch : s.toCharArray()) {\n            freq[ch - \'a\']++;\n        }\n        return freq;\n    }\n\n    private boolean freqChecker(int[] more, int[] less) {\n        for (int i = 0; i < 26; i++) {\n            if (more[i] < less[i]) return false;  \n        }\n        return true;\n    }\n}\n\n```
['Java']