Simple and Easy JAVA Solution using 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\n- Space complexity:\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 freq[] = new int[26];\n        int n = word1.length() , m = word2.length();\n        for(char ch : word2.toCharArray())\n            freq[ch-\'a\']++;\n        \n        int count = 0;\n        int left = 0 , right = 0;\n        int map[] = new int[26];\n        long ans = 0L;\n\n        while(right < n){\n            int rtCh = word1.charAt(right) - \'a\';\n            map[rtCh]++;\n            if(freq[rtCh] != 0 && freq[rtCh] > map[rtCh] - 1)\n                count++;\n            \n            while(count == m){\n                ans += n - right;\n                int lftCh = word1.charAt(left) - \'a\';\n                map[lftCh]--;\n                if(freq[lftCh] != 0 && freq[lftCh] > map[lftCh] && freq[lftCh] <= map[lftCh] + 1)\n                    count--;\n                left++;\n            }\n\n            right++;\n        }\n\n        return ans;\n    }\n}\n```
['Sliding Window', 'Java']