Simple Java Solution using freq
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+m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        int n=word1.length(),m=word2.length();\n        long count=0;\n        int[] freq1=new int[26];\n        int[] freq2=new int[26];\n        for(char c:word2.toCharArray()){\n            freq2[c-\'a\']++;\n        }\n        int l=0,validCount=0;\n        for(int r=0;r<n;r++){\n            freq1[word1.charAt(r)-\'a\']++;\n            if(freq1[word1.charAt(r)-\'a\']<=freq2[word1.charAt(r)-\'a\']){\n                validCount++;\n            }\n            while(validCount>=m){\n                count+=n-r;\n                freq1[word1.charAt(l)-\'a\']--;\n                if(freq1[word1.charAt(l)-\'a\']<freq2[word1.charAt(l)-\'a\']){\n                    validCount--;\n                }\n                l++;\n            }\n        }  \n        return count;\n    }\n}\n\n```
['Java']