scala sliding window
scala []\nobject Solution {\n  def validSubstringCount(word1: String, word2: String): Long = {\n    lazy val map2 = word2.groupMapReduce(identity)(_ => 1)(_ + _
```scala []\nobject Solution {\n  def validSubstringCount(word1: String, word2: String): Long = {\n    lazy val map2 = word2.groupMapReduce(identity)(_ => 1)(_ + _)\n    def f(i:Int=0, j:Int=0, map1: Map[Char,Int]=Map(), acc: Long=0L): Long = {\n      lazy val incMap = map1.updatedWith(word1(j)) { case None => Some(1);case Some(v) => Some(v+1)}\n      lazy val decMap = map1.updatedWith(word1(i)) { case None|Some(1) => None;case Some(v) => Some(v-1)}\n      lazy val isValid = map2.forall{case (k2,v2) => map1.getOrElse(k2,0)>=v2}\n      if (isValid) f(i+1, j, decMap, acc+word1.length-j+1)\n      else if(j<word1.length) f(i, j+1, incMap, acc)\n      else acc\n    }\n    f()\n  }\n}\n```
['Hash Table', 'String', 'Sliding Window', 'Scala']