Using z-function
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```python3 []\nclass Solution:\n    def minValidStrings(self, words: List[str], target: str) -> int:\n        n=len(target)\n        data=[0]*n\n        def process(w):\n            z,l,r = [0]*(len(w)+1), 0, 0\n            for i in range(1, len(w)):\n                z[i]=max(0, min(r-i, z[i-l]))\n                while i+z[i]<len(w) and w[i+z[i]]==w[z[i]]: z[i]+=1\n                if i+z[i]>=r: l,r=i,i+z[i]\n            l,r=0,0\n            for i in range(n):\n                zv = max(0, min(r-i, z[i-l]))\n                while i+zv<n and zv<len(w) and target[i+zv]==w[zv]: zv+=1\n                if i+zv>=r: l,r=i,i+zv\n                data[i]=max(data[i], zv)\n        for w in words: process(w)\n        res,curmax, nextmax=0,0,0\n        for i,v in enumerate(data):\n            if nextmax<i: return -1\n            nextmax=max(nextmax, i+v)\n            if curmax==i: res,curmax=res+1, nextmax\n        if nextmax<n: return -1\n        return res\n\n        \n```
['Python3']