easy java solution
\n# Code\njava []\nimport java.util.HashMap;\n\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        HashMap<Character, 
\n# Code\n```java []\nimport java.util.HashMap;\n\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        HashMap<Character, Integer> word2Count = new HashMap<>();\n        for (char c : word2.toCharArray()) {\n            word2Count.put(c, word2Count.getOrDefault(c, 0) + 1);\n        }\n\n        long validCount = 0;\n        int n = word1.length();\n        int m = word2.length();\n        HashMap<Character, Integer> currentCount = new HashMap<>();\n        int left = 0;\n        int matchedChars = 0;\n\n        for (int right = 0; right < n; right++) {\n            char rightChar = word1.charAt(right);\n            currentCount.put(rightChar, currentCount.getOrDefault(rightChar, 0) + 1);\n\n            if (word2Count.containsKey(rightChar) && currentCount.get(rightChar) <= word2Count.get(rightChar)) {\n                matchedChars++;\n            }\n\n            while (matchedChars == m) {\n                validCount += (n - right);\n                char leftChar = word1.charAt(left);\n                currentCount.put(leftChar, currentCount.get(leftChar) - 1);\n                if (word2Count.containsKey(leftChar) && currentCount.get(leftChar) < word2Count.get(leftChar)) {\n                    matchedChars--;\n                }\n                left++;\n            }\n        }\n\n        return validCount;\n    }\n}\n\n```
['Java']