Sliding window solution in Java
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:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```java []\nclass Solution {\n    public long validSubstringCount(String word1, String word2) {\n        Map<Character, Integer> symbolToCount = new HashMap<>();\n        for (char c : word2.toCharArray()) {\n            int count = symbolToCount.getOrDefault(c, 0);\n            symbolToCount.put(c, count + 1);\n        }\n        int total = word2.length();\n\n        long result = 0;\n\n        int start = 0;\n        for (int end = 0; end < word1.length(); end++) {\n            char c = word1.charAt(end);\n            int count = symbolToCount.getOrDefault(c, 0);\n            symbolToCount.put(c, count - 1);\n\n            if (symbolToCount.get(c) >= 0) {\n                total--;\n            }\n\n            while (total == 0) {\n                result += (word1.length() - 1 - end + 1);\n\n                c = word1.charAt(start);\n                count = symbolToCount.get(c);\n                symbolToCount.put(c, count + 1);\n                if (symbolToCount.get(c) > 0) {\n                    total++;\n                }\n                \n                start++;\n            }\n        }\n\n        return result;\n    }\n}\n```
['Java']