java beats 100%
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        long res = 0;\n        int keys = 0;\n        int len = word1.length();\n        int[] count = new int[26];\n        boolean[] letters = new boolean[26];\n        for (char letter : word2.toCharArray()) {\n            int index = letter - \'a\';\n            if (count[index]++ == 0) {\n                letters[index] = true;\n                keys++;\n            }\n        }\n        int start = 0, end = 0;\n        while (end < len) {\n            int index = word1.charAt(end) - \'a\';\n            if (!letters[index]) {\n                end++;\n                continue;\n            }\n            if (--count[index] == 0) --keys;\n            while (keys == 0) {\n                res += len - end;\n                int beginIndex = word1.charAt(start++) - \'a\';\n                if (!letters[beginIndex]) continue;\n                if (count[beginIndex]++ == 0) keys++;\n            }\n            end++;\n        }\n        return res;   \n    }\n}\n```
['Java']