scala z-function + jump game ii
scala version of @dmitrii_bokovikov approach https://leetcode.com/problems/minimum-number-of-valid-strings-to-form-target-ii/solutions/5790939/z-function-jump-g
scala version of @dmitrii_bokovikov approach https://leetcode.com/problems/minimum-number-of-valid-strings-to-form-target-ii/solutions/5790939/z-function-jump-game-ii/
z-function to find target maximum prefix length in words,
then jump game ii: https://leetcode.com/problems/jump-game-ii/
```scala []
object Solution {
  import util.chaining.scalaUtilChainingOps
  def minValidStrings(words: Array[String], target: String): Int =
    lazy val zmx = words.iterator.foldLeft(Map.empty[Int,Int]){case (mx,w) =>
      lazy val s = s"$w#$target."
      Iterator.range(1,s.length).foldLeft(((0,0),Map(0->0),mx)){case (((l,r),z,mx),i) =>
        lazy val zi0 = if(i<r) (r-i) min z.getOrElse(i-l,0) else 0
        lazy val zi1 = zi0 + (Iterator.range(zi0,s.length-i)
          .takeWhile(zi => s(zi) == s(i+zi)).map(_ + 1)).length
        lazy val j = i-(w.length+1)
        lazy val mx1 = if(j<0) mx else mx.updatedWith(j){_.orElse(Some(0)).map(_ max zi1)}
        (if (i+zi1>r) (i,i+zi1) else (l,r), z + (i -> zi1), mx1)
      }._3
    }
    lazy val l0 = List.range(0,target.length+1).map(i => (zmx(i)+i,i))
    if(l0.length==1) (l0.head._1-l0.head._2)*2-1
    else (List.unfold((0,l0.head,l0.tail)){case (acc,d0,l) =>
      Option.when(l.nonEmpty){
        lazy val (t,d) = l.span(_._2 <= d0._1)
        if(d0._1 == d0._2) ((-1,(acc,d0,l)),(-1,(-1,-1),l.empty))
        else ((acc+1,(acc,d0,l)),(acc+1,t.maxByOption(_._1).getOrElse(0,0),d))
      }
    }).last._1
}
```
['String', 'Greedy', 'Scala']