[Scala] Scan Twice
scala\nobject Solution {\n  def minimumScore(s: String, t: String): Int = {\n    val leftMatch = s.scanLeft(0, t.zipWithIndex) {\n      case ((_, (ct, i)+:ts), 
```scala\nobject Solution {\n  def minimumScore(s: String, t: String): Int = {\n    val leftMatch = s.scanLeft(0, t.zipWithIndex) {\n      case ((_, (ct, i)+:ts), cs) => if (ct == cs) (i, ts) else (-1, (ct, i)+:ts)\n      case _ => (-1, null)\n    }.map(_._1).drop(1)\n    val lastMatch = leftMatch.findLast(_ != -1).getOrElse(-1)\n    val lastUnmatch = (t.size - lastMatch - 1)\n    val res = s.zip(leftMatch).reverse.scanLeft(lastUnmatch, lastMatch, t.zipWithIndex.reverse) {\n      case ((_, m, (ct, i)+:ts), (cs, j)) =>\n        val nm = if (j == -1) m else j - 1\n        if (ct == cs) (i - nm - 1, nm, ts) else (Int.MaxValue, nm, (ct, i)+:ts)\n      case _ => (0, 0, null)\n    }\n    res.map(_._1).min max 0\n  }\n}\n```
[]