Sliding window, hash map
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```typescript []\nfunction validSubstringCount(word1: string, word2: string): number {\n  let map1 = new Map<string, number>();\n  let map2 = new Map<string, number>();\n\n  for (let ch of word2) {\n    map1.set(ch, (map1.get(ch) || 0) + 1);\n  }\n\n  let l = 0,\n    totalSub = 0,\n    count = 0;\n\n  for (let i = 0; i < word1.length; i++) {\n    let chr = word1.charAt(i);\n    map2.set(chr, (map2.get(chr) || 0) + 1);\n\n    if (map1.has(chr)) {\n      if (map2.get(chr)! == map1.get(chr)!) count++;\n    }\n\n    while (count >= map1.size) {\n      totalSub += word1.length - i;\n\n    //   console.log("i am calling", i);\n\n      let left = word1.charAt(l);\n      map2.set(left, map2.get(left)! - 1);\n\n      if (map1.has(left)) {\n        if (map2.get(left)! < map1.get(left)!) count--;\n      }\n\n      l++;\n    }\n  }\n\n  return totalSub;\n}\n```
['TypeScript']