Easy to understand using Java HashMap and classic sliding window algorithm
Code\njava []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        long ans = 0;\n        int n=word1.length(), m=word2
# Code\n```java []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        long ans = 0;\n        int n=word1.length(), m=word2.length();\n        Map<Character,Integer> map1 = new HashMap<>();\n        Map<Character,Integer> map2 = new HashMap<>();\n        for(int i=0;i<m;i++){\n            map2.put(word2.charAt(i), map2.getOrDefault(word2.charAt(i),0)+1);\n        }\n        int prev=0;\n        for(int i=0;i<n;i++){\n            char currCh = word1.charAt(i);\n            map1.put(currCh, map1.getOrDefault(currCh,0)+1);\n            while(itContainsAll(map1,map2)){\n                ans+=n-i;\n                char prevCh = word1.charAt(prev);\n                 if(map1.getOrDefault(prevCh,0) == 1){\n                    map1.remove(prevCh);\n                } else{\n                    map1.put(prevCh, map1.getOrDefault(prevCh,0)-1);\n                }\n                prev++;\n            }\n        }\n        return ans;\n    }\n\n    public boolean itContainsAll(Map<Character, Integer> map1, Map<Character, Integer> map2) {\n        for (Map.Entry<Character, Integer> entry : map2.entrySet()) {\n            if (!map1.containsKey(entry.getKey()) || map1.get(entry.getKey()) < entry.getValue()) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n```
['Java']