Java Solution | Sliding Window | Hash Map
Code\njava []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        char check[] = word1.toCharArray();\n        char pr
# Code\n```java []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        char check[] = word1.toCharArray();\n        char prefix[] = word2.toCharArray();\n        Map<Character, Integer> map1 = new HashMap<>();\n        Map<Character, Integer> map2 = new HashMap<>();\n        for(char ch: prefix) {\n            map2.put(ch, map2.getOrDefault(ch, 0) + 1);\n        }\n        long ans = 0;\n        for(int j = 0, i = 0; j < check.length; j++) {\n            map1.put(check[j], map1.getOrDefault(check[j], 0) + 1);\n\n            while(true) {\n                boolean found = true;\n                for(Map.Entry<Character, Integer> e: map2.entrySet()) {\n                    char ch = e.getKey();\n                    int freq = e.getValue();\n                    if(freq > map1.getOrDefault(ch, 0)) {\n                        found = false;\n                        break;\n                    }\n                }\n                if(found) {\n                    ans += check.length - j;\n                    map1.put(check[i], map1.get(check[i]) - 1);\n                    if(map1.get(check[i]) == 0) \n                        map1.remove(check[i]);\n                    i++;\n                }else {\n                    break;\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Hash Table', 'String', 'Sliding Window', 'Java']