You are an expert Python programmer. Write correct, efficient Python 3 code that solves the problem and passes all tests. Output the code in the following format: ```python
<code>
```

PROBLEM:
You are given an array of strings words and a string target.
A string x is called valid if x is a prefix of any string in words.
Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.

Example 1:

Input: words = ["abc","aaaaa","bcdef"], target = "aabcdabc"
Output: 3
Explanation:
The target string can be formed by concatenating:

Prefix of length 2 of words[1], i.e. "aa".
Prefix of length 3 of words[2], i.e. "bcd".
Prefix of length 3 of words[0], i.e. "abc".

Example 2:

Input: words = ["abababab","ab"], target = "ababaababa"
Output: 2
Explanation:
The target string can be formed by concatenating:

Prefix of length 5 of words[0], i.e. "ababa".
Prefix of length 5 of words[0], i.e. "ababa".

Example 3:

Input: words = ["abcdef"], target = "xyz"
Output: -1

Constraints:

1 <= words.length <= 100
1 <= words[i].length <= 5 * 103
The input is generated such that sum(words[i].length) <= 105.
words[i] consists only of lowercase English letters.
1 <= target.length <= 5 * 103
target consists only of lowercase English letters.

Your solution to the problem should be a method of the class Solution called minValidStrings and should pass all tests. Use the following starter code:
```python
class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:
        # Add your code here
```

SOLUTION:

Question:
PROBLEM:
You are given an array of strings words and a string target.
A string x is called valid if x is a prefix of any string in words.
Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.

Example 1:

Input: words = ["abc","aaaaa","bcdef"], target = "aabcdabc"
Output: 3
Explanation:
The target string can be formed by concatenating:

Prefix of length 2 of words[1], i.e. "aa".
Prefix of length 3 of words[2], i.e. "bcd".
Prefix of length 3 of words[0], i.e. "abc".

Example 2:

Input: words = ["abababab","ab"], target = "ababaababa"
Output: 2
Explanation:
The target string can be formed by concatenating:

Prefix of length 5 of words[0], i.e. "ababa".
Prefix of length 5 of words[0], i.e. "ababa".

Example 3:

Input: words = ["abcdef"], target = "xyz"
Output: -1

Constraints:

1 <= words.length <= 100
1 <= words[i].length <= 5 * 103
The input is generated such that sum(words[i].length) <= 105.
words[i] consists only of lowercase English letters.
1 <= target.length <= 5 * 103
target consists only of lowercase English letters.

Your solution to the problem should be a method of the class Solution called minValidStrings and should pass all tests. Use the following starter code:
```python
class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:
        # Add your code here
```

SOLUTION:

assert Solution().minValidStrings(words = ["abc"], target = "abcabc") == 2

assert Solution().minValidStrings(words = ["ab", "ba"], target = "abab") == 2

assert Solution().minValidStrings(words = ["a","b","c","d"], target = "abcdabcdabcd") == 12

assert Solution().minValidStrings(words = ["abcde", "fghij", "klmno"], target = "abcdefghijklmno") == 3

assert Solution().minValidStrings(words = ["z"], target = "zzzzzzzzzz") == 10

assert Solution().minValidStrings(words = ["abababab","ab"], target = "ababaababa") == 2

assert Solution().minValidStrings(words = ["abc", "abc", "abc"], target = "abcabcabc") == 3

assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaa") == 2

assert Solution().minValidStrings(words = ["hello","world"], target = "hello") == 1

assert Solution().minValidStrings(words = ["abcdef"], target = "xyz") == -1

assert Solution().minValidStrings(words = ["prefix","pre","fix"], target = "prefixfix") == 2

assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaaaaaa") == 4

assert Solution().minValidStrings(words = ["hello", "world"], target = "hello") == 1

assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaa") == 2

assert Solution().minValidStrings(words = ["aa", "bb", "cc"], target = "aabbcc") == 3

assert Solution().minValidStrings(words = ["ab","bc","cd"], target = "abcd") == 2

assert Solution().minValidStrings(words = ["abcd", "efgh", "ijkl"], target = "abcdefghijl") == -1

assert Solution().minValidStrings(words = ["a", "b", "c"], target = "abc") == 3

assert Solution().minValidStrings(words = ["hello","world"], target = "helloworld") == 2

assert Solution().minValidStrings(words = ["a","ab","abc"], target = "abcabcabc") == 3

assert Solution().minValidStrings(words = ["a","b","c"], target = "abc") == 3

assert Solution().minValidStrings(words = ["abc", "def", "ghi"], target = "abcdef") == 2

assert Solution().minValidStrings(words = ["prefix", "pre", "fix"], target = "prefixfix") == 2

assert Solution().minValidStrings(words = ["hello", "world"], target = "world") == 1

assert Solution().minValidStrings(words = ["a"], target = "aaaaa") == 5

assert Solution().minValidStrings(words = ["a", "ab", "abc"], target = "abc") == 1

assert Solution().minValidStrings(words = ["prefix","suffix"], target = "prefixsuffix") == 2

assert Solution().minValidStrings(words = ["abc","aaaaa","bcdef"], target = "aabcdabc") == 3

assert Solution().minValidStrings(words = ["abc", "def", "ghi", "jkl", "mno"], target = "abcdefghijklmno") == 5

assert Solution().minValidStrings(words = ["a","ab","abc","abcd"], target = "abcdabcdabcd") == 3

assert Solution().minValidStrings(words = ["prefix","pre","fix","suffix"], target = "prefixsuffix") == 2

assert Solution().minValidStrings(words = ["abc","bca","cab"], target = "abcabcabcabc") == 4

assert Solution().minValidStrings(words = ["aaa","aaaa","aaaaa","aaaaaa"], target = "aaaaaaaaaaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["jump","jum","ju","j"], target = "jumpjumpjump") == 3

assert Solution().minValidStrings(words = ["ab","ba","aba","bab","abab"], target = "ababbababababa") == 4

assert Solution().minValidStrings(words = ["brown","brow","bro","br","b"], target = "brownbrownbrow") == 3

assert Solution().minValidStrings(words = ["aaa", "aa", "a", "aaaa"], target = "aaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["abc", "def", "ghi", "jkl"], target = "abcdefghijk") == 4

assert Solution().minValidStrings(words = ["abcdefghij","jihgfedcba","abcdefgh","hgfedcba"], target = "abcdefghijhgfedcbahgfedcba") == 3

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno"], target = "abcdefghijklmnopqrstuvwxyza") == -1

assert Solution().minValidStrings(words = ["lazy","laz","la","l"], target = "lazylazy") == 2

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaa") == 4

assert Solution().minValidStrings(words = ["one","two","three","four","five","six","seven","eight","nine","ten"], target = "onetwothreefourfivesixseveneightnineten") == 10

assert Solution().minValidStrings(words = ["repeated","repeat","re","rep","repe"], target = "repeatedrepeated") == 2

assert Solution().minValidStrings(words = ["abcd","bcd","cd","d"], target = "abcdbcdbcd") == 3

assert Solution().minValidStrings(words = ["one","two","three"], target = "onetwothree") == 3

assert Solution().minValidStrings(words = ["hello","world","hello","world"], target = "helloworldhello") == 3

assert Solution().minValidStrings(words = ["xyz","zyx","yz","zx","yx"], target = "zyxzyxzyx") == 3

assert Solution().minValidStrings(words = ["prefix","pre","fix","fixx","fixxx"], target = "prefixfixfixxxfixfixfixx") == 6

assert Solution().minValidStrings(words = ["one","two","three","four"], target = "onetwothreefour") == 4

assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyzyxzyzyx") == -1

assert Solution().minValidStrings(words = ["longprefix","longerprefix","longestprefix"], target = "longestprefixlongprefixlongerprefix") == 3

assert Solution().minValidStrings(words = ["dog","do","d"], target = "dogdogdog") == 3

assert Solution().minValidStrings(words = ["short","longer","longestword"], target = "shortlongerlongestwordshortlongerlongestwordshortlongerlongestword") == 9

assert Solution().minValidStrings(words = ["abcd","abc","ab","a"], target = "abcabcabcabc") == 4

assert Solution().minValidStrings(words = ["abcdefg","bcdefgh","cdefghi","defghij","efghijk"], target = "abcdefghijk") == 2

assert Solution().minValidStrings(words = ["unique","words","only","here"], target = "uniquewordsonlyhere") == 4

assert Solution().minValidStrings(words = ["abcdefgh","ijklmnop","qrstuvwx","yz"], target = "abcdefghijklmnopqrstuvwxyzyz") == 5

assert Solution().minValidStrings(words = ["abab","baba","abba","baab","aaaa"], target = "ababbabaabbaab") == 4

assert Solution().minValidStrings(words = ["hello","world","hello","world"], target = "helloworldhelloworld") == 4

assert Solution().minValidStrings(words = ["longword","longerword","longestword"], target = "longwordlongerwordlongestwordlongestwordlongestword") == 5

assert Solution().minValidStrings(words = ["hello","hell","he","h"], target = "hellohello") == 2

assert Solution().minValidStrings(words = ["prefix", "prefixprefix", "prefixprefixprefix"], target = "prefixprefixprefixprefix") == 2

assert Solution().minValidStrings(words = ["ab","abc","abcd"], target = "abcabcdab") == 3

assert Solution().minValidStrings(words = ["aaa","aab","aac","aad"], target = "aaabaaacaaad") == 6

assert Solution().minValidStrings(words = ["small","big","medium"], target = "smallbigmediumbig") == 4

assert Solution().minValidStrings(words = ["one", "two", "three", "four"], target = "onetwothreefour") == 4

assert Solution().minValidStrings(words = ["hello","world","hel","lo","wor","ld"], target = "helloworld") == 2

assert Solution().minValidStrings(words = ["giraffe","gira","gir","gi","g"], target = "giraffegiraffe") == 2

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

assert Solution().minValidStrings(words = ["one","on","o"], target = "ononeone") == 3

assert Solution().minValidStrings(words = ["x","y","z","xy","yz","xz","xyz"], target = "xyzxyzxyz") == 3

assert Solution().minValidStrings(words = ["prefix", "fix", "pre", "prefixfix"], target = "prefixprefix") == 2

assert Solution().minValidStrings(words = ["prefix","pre","fix","prefixfix"], target = "prefixprefixfix") == 2

assert Solution().minValidStrings(words = ["aabb","ab","aab","aa"], target = "aabbabaaababaab") == 6

assert Solution().minValidStrings(words = ["pqr","pq","p"], target = "pqrpqppqrpqpp") == 7

assert Solution().minValidStrings(words = ["abc","abcabc","abcabcabc","abcabcabcabc"], target = "abcabcabcabcabcabcabcabcabcabc") == 3

assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzyxzyz") == -1

assert Solution().minValidStrings(words = ["prefix","suffix","pre","fix","postfix"], target = "prefixpostfix") == 2

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcdeabcdeabcde") == 15

assert Solution().minValidStrings(words = ["abcd","abcde","abcdef","abcdefg"], target = "abcdefgabcdefgabcdefg") == 3

assert Solution().minValidStrings(words = ["abcd","bcde","cdef","defg"], target = "abcdefg") == 2

assert Solution().minValidStrings(words = ["abcd", "abc", "ab", "a"], target = "abcdabc") == 2

assert Solution().minValidStrings(words = ["abc","bcd","cde","def"], target = "abcdef") == 2

assert Solution().minValidStrings(words = ["hello","hellohello","hellohellohello"], target = "hellohellohellohellohellohello") == 2

assert Solution().minValidStrings(words = ["quick","qui","qu","q"], target = "quickquick") == 2

assert Solution().minValidStrings(words = ["xyz","yz","z"], target = "xyzxyz") == 2

assert Solution().minValidStrings(words = ["longword","long","lo","l"], target = "longwordlongwordlongword") == 3

assert Solution().minValidStrings(words = ["panda","pan","pa","p"], target = "pandapanpapanda") == 4

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl"], target = "abcdefghijkl") == 4

assert Solution().minValidStrings(words = ["abc","b","c"], target = "abcbabcbabc") == 5

assert Solution().minValidStrings(words = ["repeated","repeat","rep","r"], target = "repeatedrepeatedrepeated") == 3

assert Solution().minValidStrings(words = ["zebra","zeb","ze","z"], target = "zebrazebrazebra") == 3

assert Solution().minValidStrings(words = ["abc","cba","bac"], target = "abcbacbac") == 3

assert Solution().minValidStrings(words = ["a", "ab", "abc", "abcd"], target = "abcdabcdabcd") == 3

assert Solution().minValidStrings(words = ["aaaa","aaa","aa","a"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa"], target = "aaaaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["ab","a","b"], target = "abababababab") == 6

assert Solution().minValidStrings(words = ["aaaa","aaa","aa","a"], target = "aaaaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["longprefix","prefix","fix","suffix"], target = "longprefixsuffix") == 2

assert Solution().minValidStrings(words = ["fox","fo","f"], target = "foxfoxfoxfox") == 4

assert Solution().minValidStrings(words = ["abcd","abc","ab","a"], target = "abcdabcaba") == 4

assert Solution().minValidStrings(words = ["pqr","pq","p"], target = "ppppqqqrrr") == -1

assert Solution().minValidStrings(words = ["prefix", "prefi", "pref", "pre", "pr"], target = "prefixprefix") == 2

assert Solution().minValidStrings(words = ["cat","ca","c"], target = "catcatcatcat") == 4

assert Solution().minValidStrings(words = ["prefix","pref","pre","p"], target = "prefixprefix") == 2

assert Solution().minValidStrings(words = ["abc","bcd","cde","def"], target = "abcdefg") == -1

assert Solution().minValidStrings(words = ["apple","banana","cherry"], target = "applebananaapple") == 3

assert Solution().minValidStrings(words = ["partial","part","par","pa","p"], target = "partialpartparpap") == 5

assert Solution().minValidStrings(words = ["abcd","abc","ab","a"], target = "abcdabcab") == 3

assert Solution().minValidStrings(words = ["prefix","pre","fix","fixx"], target = "prefixprefixfixfixxfix") == 5

assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaaaaaaaaaaaa") == 6

assert Solution().minValidStrings(words = ["prefix","prefixing","pre","fix","fixing"], target = "prefixprefixfix") == 3

assert Solution().minValidStrings(words = ["qwerty","werty","erty","rty","ty","y","yt","tyu"], target = "qwertytyutytutytutytutytutytutytutytutu") == -1

assert Solution().minValidStrings(words = ["abac","bac","cab","abc"], target = "abacbacabc") == 3

assert Solution().minValidStrings(words = ["over","ove","ov","o"], target = "overoverover") == 3

assert Solution().minValidStrings(words = ["aaaaa","aaaa","aaa","aa","a"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 21

assert Solution().minValidStrings(words = ["abcde","cdefg","efghi","fghij"], target = "abcdefghij") == 2

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "edcba") == 5

assert Solution().minValidStrings(words = ["one","two","three"], target = "onetwothreeonetwo") == 5

assert Solution().minValidStrings(words = ["abc","ab","a"], target = "abcabcabc") == 3

assert Solution().minValidStrings(words = ["a","ab","abc","abcd"], target = "abcdabcd") == 2

assert Solution().minValidStrings(words = ["hello","hi","h","he","hel"], target = "hellohellohi") == 3

assert Solution().minValidStrings(words = ["xyz", "zyx", "yyz", "xzy"], target = "zyxzyxzyx") == 3

assert Solution().minValidStrings(words = ["same","same","same"], target = "samesamesamesamesame") == 5

assert Solution().minValidStrings(words = ["pqr","pr","qr","r","pq","q"], target = "pqrprqrpqr") == 4

assert Solution().minValidStrings(words = ["test", "testing", "testcase"], target = "testtestingtestcase") == 3

assert Solution().minValidStrings(words = ["abcd","bcd","cde","def","efg","fgh"], target = "abcdefg") == 2

assert Solution().minValidStrings(words = ["abc", "abcd", "abcde"], target = "abcdeabcdeabcde") == 3

assert Solution().minValidStrings(words = ["complex","words","example"], target = "complexwordscomplex") == 3

assert Solution().minValidStrings(words = ["elephant","elepha","eleph","elep","ele","el","e"], target = "elephantelephant") == 2

assert Solution().minValidStrings(words = ["abc", "bc", "c", "abcd"], target = "abcabcabc") == 3

assert Solution().minValidStrings(words = ["xyz","zyx","yzx"], target = "xyzzyxyzzyx") == 4

assert Solution().minValidStrings(words = ["xy","xyz","xyza","xyzabc"], target = "xyzabcxyzabcxyz") == 3

assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyxyzyx") == -1

assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j"], target = "abcdefghij") == 10

assert Solution().minValidStrings(words = ["aaa","bbb","ccc"], target = "aaabbbccc") == 3

assert Solution().minValidStrings(words = ["abc", "abcd", "ab", "bcde"], target = "abcdabcde") == 3

assert Solution().minValidStrings(words = ["a","ab","abc","abcd","abcde"], target = "abcdeabcde") == 2

assert Solution().minValidStrings(words = ["xyz","zyx","yxz","yxzyx"], target = "xyzzyxzyxzyxzyxzyx") == 6

assert Solution().minValidStrings(words = ["zzz","zz","z"], target = "zzzzzzzzzzzzzzzzzzzz") == 7

assert Solution().minValidStrings(words = ["z", "yz", "xyz", "wxyz"], target = "wxyzwxyzwxyz") == 3

assert Solution().minValidStrings(words = ["abc","acb","bac","bca","cab","cba"], target = "abcacbabcabc") == 4

assert Solution().minValidStrings(words = ["abcde","bcd","cde","efg"], target = "abcdecdefg") == 3

assert Solution().minValidStrings(words = ["repeated","repeate","repea","repe","rep","re","r"], target = "repeatedrepeatedrepeated") == 3

assert Solution().minValidStrings(words = ["aaaa", "aa", "a"], target = "aaaaaaaaaaaaaaaaaaaaaaaa") == 6

assert Solution().minValidStrings(words = ["onetwo", "one", "two", "three"], target = "onetwothreeonetwo") == 3

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl"], target = "abcdefghijk") == 4

Answer: assert Solution().minValidStrings(words = ["abc"], target = "abcabc") == 2

Answer: assert Solution().minValidStrings(words = ["ab", "ba"], target = "abab") == 2

Answer: assert Solution().minValidStrings(words = ["a","b","c","d"], target = "abcdabcdabcd") == 12

Answer: assert Solution().minValidStrings(words = ["abcde", "fghij", "klmno"], target = "abcdefghijklmno") == 3

Answer: assert Solution().minValidStrings(words = ["z"], target = "zzzzzzzzzz") == 10

Answer: assert Solution().minValidStrings(words = ["abababab","ab"], target = "ababaababa") == 2

Answer: assert Solution().minValidStrings(words = ["abc", "abc", "abc"], target = "abcabcabc") == 3

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaa") == 2

Answer: assert Solution().minValidStrings(words = ["hello","world"], target = "hello") == 1

Answer: assert Solution().minValidStrings(words = ["abcdef"], target = "xyz") == -1

Answer: assert Solution().minValidStrings(words = ["prefix","pre","fix"], target = "prefixfix") == 2

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaaaaaa") == 4

Answer: assert Solution().minValidStrings(words = ["hello", "world"], target = "hello") == 1

Answer: assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaa") == 2

Answer: assert Solution().minValidStrings(words = ["aa", "bb", "cc"], target = "aabbcc") == 3

Answer: assert Solution().minValidStrings(words = ["ab","bc","cd"], target = "abcd") == 2

Answer: assert Solution().minValidStrings(words = ["abcd", "efgh", "ijkl"], target = "abcdefghijl") == -1

Answer: assert Solution().minValidStrings(words = ["a", "b", "c"], target = "abc") == 3

Answer: assert Solution().minValidStrings(words = ["hello","world"], target = "helloworld") == 2

Answer: assert Solution().minValidStrings(words = ["a","ab","abc"], target = "abcabcabc") == 3

Answer: assert Solution().minValidStrings(words = ["a","b","c"], target = "abc") == 3

Answer: assert Solution().minValidStrings(words = ["abc", "def", "ghi"], target = "abcdef") == 2

Answer: assert Solution().minValidStrings(words = ["prefix", "pre", "fix"], target = "prefixfix") == 2

Answer: assert Solution().minValidStrings(words = ["hello", "world"], target = "world") == 1

Answer: assert Solution().minValidStrings(words = ["a"], target = "aaaaa") == 5

Answer: assert Solution().minValidStrings(words = ["a", "ab", "abc"], target = "abc") == 1

Answer: assert Solution().minValidStrings(words = ["prefix","suffix"], target = "prefixsuffix") == 2

Answer: assert Solution().minValidStrings(words = ["abc","aaaaa","bcdef"], target = "aabcdabc") == 3

Answer: assert Solution().minValidStrings(words = ["abc", "def", "ghi", "jkl", "mno"], target = "abcdefghijklmno") == 5

Answer: assert Solution().minValidStrings(words = ["a","ab","abc","abcd"], target = "abcdabcdabcd") == 3

Answer: assert Solution().minValidStrings(words = ["prefix","pre","fix","suffix"], target = "prefixsuffix") == 2

Answer: assert Solution().minValidStrings(words = ["abc","bca","cab"], target = "abcabcabcabc") == 4

Answer: assert Solution().minValidStrings(words = ["aaa","aaaa","aaaaa","aaaaaa"], target = "aaaaaaaaaaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["jump","jum","ju","j"], target = "jumpjumpjump") == 3

Answer: assert Solution().minValidStrings(words = ["ab","ba","aba","bab","abab"], target = "ababbababababa") == 4

Answer: assert Solution().minValidStrings(words = ["brown","brow","bro","br","b"], target = "brownbrownbrow") == 3

Answer: assert Solution().minValidStrings(words = ["aaa", "aa", "a", "aaaa"], target = "aaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["abc", "def", "ghi", "jkl"], target = "abcdefghijk") == 4

Answer: assert Solution().minValidStrings(words = ["abcdefghij","jihgfedcba","abcdefgh","hgfedcba"], target = "abcdefghijhgfedcbahgfedcba") == 3

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno"], target = "abcdefghijklmnopqrstuvwxyza") == -1

Answer: assert Solution().minValidStrings(words = ["lazy","laz","la","l"], target = "lazylazy") == 2

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaa") == 4

Answer: assert Solution().minValidStrings(words = ["one","two","three","four","five","six","seven","eight","nine","ten"], target = "onetwothreefourfivesixseveneightnineten") == 10

Answer: assert Solution().minValidStrings(words = ["repeated","repeat","re","rep","repe"], target = "repeatedrepeated") == 2

Answer: assert Solution().minValidStrings(words = ["abcd","bcd","cd","d"], target = "abcdbcdbcd") == 3

Answer: assert Solution().minValidStrings(words = ["one","two","three"], target = "onetwothree") == 3

Answer: assert Solution().minValidStrings(words = ["hello","world","hello","world"], target = "helloworldhello") == 3

Answer: assert Solution().minValidStrings(words = ["xyz","zyx","yz","zx","yx"], target = "zyxzyxzyx") == 3

Answer: assert Solution().minValidStrings(words = ["prefix","pre","fix","fixx","fixxx"], target = "prefixfixfixxxfixfixfixx") == 6

Answer: assert Solution().minValidStrings(words = ["one","two","three","four"], target = "onetwothreefour") == 4

Answer: assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyzyxzyzyx") == -1

Answer: assert Solution().minValidStrings(words = ["longprefix","longerprefix","longestprefix"], target = "longestprefixlongprefixlongerprefix") == 3

Answer: assert Solution().minValidStrings(words = ["dog","do","d"], target = "dogdogdog") == 3

Answer: assert Solution().minValidStrings(words = ["short","longer","longestword"], target = "shortlongerlongestwordshortlongerlongestwordshortlongerlongestword") == 9

Answer: assert Solution().minValidStrings(words = ["abcd","abc","ab","a"], target = "abcabcabcabc") == 4

Answer: assert Solution().minValidStrings(words = ["abcdefg","bcdefgh","cdefghi","defghij","efghijk"], target = "abcdefghijk") == 2

Answer: assert Solution().minValidStrings(words = ["unique","words","only","here"], target = "uniquewordsonlyhere") == 4

Answer: assert Solution().minValidStrings(words = ["abcdefgh","ijklmnop","qrstuvwx","yz"], target = "abcdefghijklmnopqrstuvwxyzyz") == 5

Answer: assert Solution().minValidStrings(words = ["abab","baba","abba","baab","aaaa"], target = "ababbabaabbaab") == 4

Answer: assert Solution().minValidStrings(words = ["hello","world","hello","world"], target = "helloworldhelloworld") == 4

Answer: assert Solution().minValidStrings(words = ["longword","longerword","longestword"], target = "longwordlongerwordlongestwordlongestwordlongestword") == 5

Answer: assert Solution().minValidStrings(words = ["hello","hell","he","h"], target = "hellohello") == 2

Answer: assert Solution().minValidStrings(words = ["prefix", "prefixprefix", "prefixprefixprefix"], target = "prefixprefixprefixprefix") == 2

Answer: assert Solution().minValidStrings(words = ["ab","abc","abcd"], target = "abcabcdab") == 3

Answer: assert Solution().minValidStrings(words = ["aaa","aab","aac","aad"], target = "aaabaaacaaad") == 6

Answer: assert Solution().minValidStrings(words = ["small","big","medium"], target = "smallbigmediumbig") == 4

Answer: assert Solution().minValidStrings(words = ["one", "two", "three", "four"], target = "onetwothreefour") == 4

Answer: assert Solution().minValidStrings(words = ["hello","world","hel","lo","wor","ld"], target = "helloworld") == 2

Answer: assert Solution().minValidStrings(words = ["giraffe","gira","gir","gi","g"], target = "giraffegiraffe") == 2

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

Answer: assert Solution().minValidStrings(words = ["one","on","o"], target = "ononeone") == 3

Answer: assert Solution().minValidStrings(words = ["x","y","z","xy","yz","xz","xyz"], target = "xyzxyzxyz") == 3

Answer: assert Solution().minValidStrings(words = ["prefix", "fix", "pre", "prefixfix"], target = "prefixprefix") == 2

Answer: assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"], target = "abcdefghijklmnopqrstuvwxyz") == 26

Answer: assert Solution().minValidStrings(words = ["prefix","pre","fix","prefixfix"], target = "prefixprefixfix") == 2

Answer: assert Solution().minValidStrings(words = ["aabb","ab","aab","aa"], target = "aabbabaaababaab") == 6

Answer: assert Solution().minValidStrings(words = ["pqr","pq","p"], target = "pqrpqppqrpqpp") == 7

Answer: assert Solution().minValidStrings(words = ["abc","abcabc","abcabcabc","abcabcabcabc"], target = "abcabcabcabcabcabcabcabcabcabc") == 3

Answer: assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzyxzyz") == -1

Answer: assert Solution().minValidStrings(words = ["prefix","suffix","pre","fix","postfix"], target = "prefixpostfix") == 2

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcdeabcdeabcde") == 15

Answer: assert Solution().minValidStrings(words = ["abcd","abcde","abcdef","abcdefg"], target = "abcdefgabcdefgabcdefg") == 3

Answer: assert Solution().minValidStrings(words = ["abcd","bcde","cdef","defg"], target = "abcdefg") == 2

Answer: assert Solution().minValidStrings(words = ["abcd", "abc", "ab", "a"], target = "abcdabc") == 2

Answer: assert Solution().minValidStrings(words = ["abc","bcd","cde","def"], target = "abcdef") == 2

Answer: assert Solution().minValidStrings(words = ["hello","hellohello","hellohellohello"], target = "hellohellohellohellohellohello") == 2

Answer: assert Solution().minValidStrings(words = ["quick","qui","qu","q"], target = "quickquick") == 2

Answer: assert Solution().minValidStrings(words = ["xyz","yz","z"], target = "xyzxyz") == 2

Answer: assert Solution().minValidStrings(words = ["longword","long","lo","l"], target = "longwordlongwordlongword") == 3

Answer: assert Solution().minValidStrings(words = ["panda","pan","pa","p"], target = "pandapanpapanda") == 4

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl"], target = "abcdefghijkl") == 4

Answer: assert Solution().minValidStrings(words = ["abc","b","c"], target = "abcbabcbabc") == 5

Answer: assert Solution().minValidStrings(words = ["repeated","repeat","rep","r"], target = "repeatedrepeatedrepeated") == 3

Answer: assert Solution().minValidStrings(words = ["zebra","zeb","ze","z"], target = "zebrazebrazebra") == 3

Answer: assert Solution().minValidStrings(words = ["abc","cba","bac"], target = "abcbacbac") == 3

Answer: assert Solution().minValidStrings(words = ["a", "ab", "abc", "abcd"], target = "abcdabcdabcd") == 3

Answer: assert Solution().minValidStrings(words = ["aaaa","aaa","aa","a"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa"], target = "aaaaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["ab","a","b"], target = "abababababab") == 6

Answer: assert Solution().minValidStrings(words = ["aaaa","aaa","aa","a"], target = "aaaaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["longprefix","prefix","fix","suffix"], target = "longprefixsuffix") == 2

Answer: assert Solution().minValidStrings(words = ["fox","fo","f"], target = "foxfoxfoxfox") == 4

Answer: assert Solution().minValidStrings(words = ["abcd","abc","ab","a"], target = "abcdabcaba") == 4

Answer: assert Solution().minValidStrings(words = ["pqr","pq","p"], target = "ppppqqqrrr") == -1

Answer: assert Solution().minValidStrings(words = ["prefix", "prefi", "pref", "pre", "pr"], target = "prefixprefix") == 2

Answer: assert Solution().minValidStrings(words = ["cat","ca","c"], target = "catcatcatcat") == 4

Answer: assert Solution().minValidStrings(words = ["prefix","pref","pre","p"], target = "prefixprefix") == 2

Answer: assert Solution().minValidStrings(words = ["abc","bcd","cde","def"], target = "abcdefg") == -1

Answer: assert Solution().minValidStrings(words = ["apple","banana","cherry"], target = "applebananaapple") == 3

Answer: assert Solution().minValidStrings(words = ["partial","part","par","pa","p"], target = "partialpartparpap") == 5

Answer: assert Solution().minValidStrings(words = ["abcd","abc","ab","a"], target = "abcdabcab") == 3

Answer: assert Solution().minValidStrings(words = ["prefix","pre","fix","fixx"], target = "prefixprefixfixfixxfix") == 5

Answer: assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaaaaaaaaaaaa") == 6

Answer: assert Solution().minValidStrings(words = ["prefix","prefixing","pre","fix","fixing"], target = "prefixprefixfix") == 3

Answer: assert Solution().minValidStrings(words = ["qwerty","werty","erty","rty","ty","y","yt","tyu"], target = "qwertytyutytutytutytutytutytutytutytutu") == -1

Answer: assert Solution().minValidStrings(words = ["abac","bac","cab","abc"], target = "abacbacabc") == 3

Answer: assert Solution().minValidStrings(words = ["over","ove","ov","o"], target = "overoverover") == 3

Answer: assert Solution().minValidStrings(words = ["aaaaa","aaaa","aaa","aa","a"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 21

Answer: assert Solution().minValidStrings(words = ["abcde","cdefg","efghi","fghij"], target = "abcdefghij") == 2

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "edcba") == 5

Answer: assert Solution().minValidStrings(words = ["one","two","three"], target = "onetwothreeonetwo") == 5

Answer: assert Solution().minValidStrings(words = ["abc","ab","a"], target = "abcabcabc") == 3

Answer: assert Solution().minValidStrings(words = ["a","ab","abc","abcd"], target = "abcdabcd") == 2

Answer: assert Solution().minValidStrings(words = ["hello","hi","h","he","hel"], target = "hellohellohi") == 3

Answer: assert Solution().minValidStrings(words = ["xyz", "zyx", "yyz", "xzy"], target = "zyxzyxzyx") == 3

Answer: assert Solution().minValidStrings(words = ["same","same","same"], target = "samesamesamesamesame") == 5

Answer: assert Solution().minValidStrings(words = ["pqr","pr","qr","r","pq","q"], target = "pqrprqrpqr") == 4

Answer: assert Solution().minValidStrings(words = ["test", "testing", "testcase"], target = "testtestingtestcase") == 3

Answer: assert Solution().minValidStrings(words = ["abcd","bcd","cde","def","efg","fgh"], target = "abcdefg") == 2

Answer: assert Solution().minValidStrings(words = ["abc", "abcd", "abcde"], target = "abcdeabcdeabcde") == 3

Answer: assert Solution().minValidStrings(words = ["complex","words","example"], target = "complexwordscomplex") == 3

Answer: assert Solution().minValidStrings(words = ["elephant","elepha","eleph","elep","ele","el","e"], target = "elephantelephant") == 2

Answer: assert Solution().minValidStrings(words = ["abc", "bc", "c", "abcd"], target = "abcabcabc") == 3

Answer: assert Solution().minValidStrings(words = ["xyz","zyx","yzx"], target = "xyzzyxyzzyx") == 4

Answer: assert Solution().minValidStrings(words = ["xy","xyz","xyza","xyzabc"], target = "xyzabcxyzabcxyz") == 3

Answer: assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyxyzyx") == -1

Answer: assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j"], target = "abcdefghij") == 10

Answer: assert Solution().minValidStrings(words = ["aaa","bbb","ccc"], target = "aaabbbccc") == 3

Answer: assert Solution().minValidStrings(words = ["abc", "abcd", "ab", "bcde"], target = "abcdabcde") == 3

Answer: assert Solution().minValidStrings(words = ["a","ab","abc","abcd","abcde"], target = "abcdeabcde") == 2

Answer: assert Solution().minValidStrings(words = ["xyz","zyx","yxz","yxzyx"], target = "xyzzyxzyxzyxzyxzyx") == 6

Answer: assert Solution().minValidStrings(words = ["zzz","zz","z"], target = "zzzzzzzzzzzzzzzzzzzz") == 7

Answer: assert Solution().minValidStrings(words = ["z", "yz", "xyz", "wxyz"], target = "wxyzwxyzwxyz") == 3

Answer: assert Solution().minValidStrings(words = ["abc","acb","bac","bca","cab","cba"], target = "abcacbabcabc") == 4

Answer: assert Solution().minValidStrings(words = ["abcde","bcd","cde","efg"], target = "abcdecdefg") == 3

Answer: assert Solution().minValidStrings(words = ["repeated","repeate","repea","repe","rep","re","r"], target = "repeatedrepeatedrepeated") == 3

Answer: assert Solution().minValidStrings(words = ["aaaa", "aa", "a"], target = "aaaaaaaaaaaaaaaaaaaaaaaa") == 6

Answer: assert Solution().minValidStrings(words = ["onetwo", "one", "two", "three"], target = "onetwothreeonetwo") == 3

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl"], target = "abcdefghijk") == 4

import random
import functools
import collections
import string
import math
import datetime

from typing import *
from functools import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from string import *
from operator import *
from math import *

inf = float('inf')

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def list_node(values: list):
    if not values:
        return None
    head = ListNode(values[0])
    p = head
    for val in values[1:]:
        node = ListNode(val)
        p.next = node
        p = node
    return head

def is_same_list(p1, p2):
    if p1 is None and p2 is None:
        return True
    if not p1 or not p2:
        return False
    return p1.val == p2.val and is_same_list(p1.next, p2.next)

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def tree_node(values: list):
    if not values:
        return None
    root = TreeNode(values[0])
    i = 1
    queue = deque()
    queue.append(root)
    while queue:
        node = queue.popleft()
        if i < len(values) and values[i] is not None:
            node.left = TreeNode(values[i])
            queue.append(node.left)
        i += 1
        if i < len(values) and values[i] is not None:
            node.right = TreeNode(values[i])
            queue.append(node.right)
        i += 1
    return root

def is_same_tree(p, q):
    if not p and not q:
        return True
    elif not p or not q:
        return False
    elif p.val != q.val:
        return False
    else:
        return is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right)

def min(a: int, b: int) -> int:
    return a if a < b else b

class Trie:
    def __init__(self):
        self.children: List[Optional[Trie]] = [None] * 26

    def insert(self, w: str):
        node = self
        for i in map(lambda c: ord(c) - 97, w):
            if node.children[i] is None:
                node.children[i] = Trie()
            node = node.children[i]

class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:
        @cache
        def dfs(i: int) -> int:
            if i >= n:
                return 0
            node = trie
            ans = inf
            for j in range(i, n):
                k = ord(target[j]) - 97
                if node.children[k] is None:
                    break
                node = node.children[k]
                ans = min(ans, 1 + dfs(j + 1))
            return ans

        trie = Trie()
        for w in words:
            trie.insert(w)
        n = len(target)
        ans = dfs(0)
        return ans if ans < inf else -1

class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:


You are an expert Python programmer. Write correct, efficient Python 3 code that solves the problem and passes all tests. Output the code in the following format: ```python
<code>
```

PROBLEM:
You are given an array of strings words and a string target.
A string x is called valid if x is a prefix of any string in words.
Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.

Example 1:

Input: words = ["abc","aaaaa","bcdef"], target = "aabcdabc"
Output: 3
Explanation:
The target string can be formed by concatenating:

Prefix of length 2 of words[1], i.e. "aa".
Prefix of length 3 of words[2], i.e. "bcd".
Prefix of length 3 of words[0], i.e. "abc".

Example 2:

Input: words = ["abababab","ab"], target = "ababaababa"
Output: 2
Explanation:
The target string can be formed by concatenating:

Prefix of length 5 of words[0], i.e. "ababa".
Prefix of length 5 of words[0], i.e. "ababa".

Example 3:

Input: words = ["abcdef"], target = "xyz"
Output: -1

Constraints:

1 <= words.length <= 100
1 <= words[i].length <= 5 * 104
The input is generated such that sum(words[i].length) <= 105.
words[i] consists only of lowercase English letters.
1 <= target.length <= 5 * 104
target consists only of lowercase English letters.

Your solution to the problem should be a method of the class Solution called minValidStrings and should pass all tests. Use the following starter code:
```python
class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:
        # Add your code here
```

SOLUTION:

Question:
PROBLEM:
You are given an array of strings words and a string target.
A string x is called valid if x is a prefix of any string in words.
Return the minimum number of valid strings that can be concatenated to form target. If it is not possible to form target, return -1.

Example 1:

Input: words = ["abc","aaaaa","bcdef"], target = "aabcdabc"
Output: 3
Explanation:
The target string can be formed by concatenating:

Prefix of length 2 of words[1], i.e. "aa".
Prefix of length 3 of words[2], i.e. "bcd".
Prefix of length 3 of words[0], i.e. "abc".

Example 2:

Input: words = ["abababab","ab"], target = "ababaababa"
Output: 2
Explanation:
The target string can be formed by concatenating:

Prefix of length 5 of words[0], i.e. "ababa".
Prefix of length 5 of words[0], i.e. "ababa".

Example 3:

Input: words = ["abcdef"], target = "xyz"
Output: -1

Constraints:

1 <= words.length <= 100
1 <= words[i].length <= 5 * 104
The input is generated such that sum(words[i].length) <= 105.
words[i] consists only of lowercase English letters.
1 <= target.length <= 5 * 104
target consists only of lowercase English letters.

Your solution to the problem should be a method of the class Solution called minValidStrings and should pass all tests. Use the following starter code:
```python
class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:
        # Add your code here
```

SOLUTION:

assert Solution().minValidStrings(words = ["abc"], target = "abcabc") == 2

assert Solution().minValidStrings(words = ["a"], target = "a") == 1

assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaaaa") == 3

assert Solution().minValidStrings(words = ["xyz"], target = "xyz") == 1

assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["a"], target = "aaaaaaaaaa") == 10

assert Solution().minValidStrings(words = ["abababab","ab"], target = "ababaababa") == 2

assert Solution().minValidStrings(words = ["abcde"], target = "abcde") == 1

assert Solution().minValidStrings(words = ["abc","aaaaa","bcdef"], target = "aabcdabc") == 3

assert Solution().minValidStrings(words = ["hello","world"], target = "hello") == 1

assert Solution().minValidStrings(words = ["abcd", "efgh", "ijkl"], target = "abcdefghij") == 3

assert Solution().minValidStrings(words = ["abcdef"], target = "xyz") == -1

assert Solution().minValidStrings(words = ["abc","abc","abc"], target = "abcabc") == 2

assert Solution().minValidStrings(words = ["z", "y", "x"], target = "zyxzyxzyx") == 9

assert Solution().minValidStrings(words = ["abcdef", "ghijkl"], target = "abcdefghijkl") == 2

assert Solution().minValidStrings(words = ["abc", "def", "ghi"], target = "abcdefghi") == 3

assert Solution().minValidStrings(words = ["hello","world"], target = "helloworld") == 2

assert Solution().minValidStrings(words = ["abc","def","ghi"], target = "abcdef") == 2

assert Solution().minValidStrings(words = ["a","b","c"], target = "abc") == 3

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl"], target = "abcdefghijklop") == -1

assert Solution().minValidStrings(words = ["z"], target = "zzzzz") == 5

assert Solution().minValidStrings(words = ["abcd","efgh","ijkl"], target = "abcdefghijklijkl") == 4

assert Solution().minValidStrings(words = ["hello","helloo","hellooo","helloooo"], target = "helloooohelloooohelloooohelloooo") == 4

assert Solution().minValidStrings(words = ["mnop","mnopqr","mnopqrst","mnopqrstu","mnopqrstuv"], target = "mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstu") == 4

assert Solution().minValidStrings(words = ["z", "zz", "zzz", "zzzz", "zzzzz"], target = "zzzzzzzzzzzzzz") == 3

assert Solution().minValidStrings(words = ["zzzzz","zzzz","zzz","zz","z"], target = "zzzzzzzzzzzzzzzzzzzzzz") == 5

assert Solution().minValidStrings(words = ["hello","world","hel","wor"], target = "helloworldhelloworld") == 4

assert Solution().minValidStrings(words = ["abcd", "bcde", "cdef", "defg"], target = "abcdefghijklmnop") == -1

assert Solution().minValidStrings(words = ["abcdef","bcdef","cdef","def","ef","f"], target = "abcdefbcdefcdef") == 3

assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzxyxyxzyzyx") == -1

assert Solution().minValidStrings(words = ["start", "startstart", "startstartstart"], target = "startstartstart") == 1

assert Solution().minValidStrings(words = ["example", "sample", "exam", "ple", "samplesample"], target = "examplesamplesampleple") == 3

assert Solution().minValidStrings(words = ["z", "zy", "zyx", "zyxw"], target = "zyxwzyxwzyxwzyxw") == 4

assert Solution().minValidStrings(words = ["abcdef","fedcba","abc","cba","def","efd"], target = "abcdefcbaefdefabc") == 5

assert Solution().minValidStrings(words = ["abcd", "efgh", "ijkl"], target = "abcdefghijklijk") == 4

assert Solution().minValidStrings(words = ["aabbcc","bbaacc","ccaabb","aabbbccc","abbcccaab"], target = "aabbccbbcccaababbcccaab") == 5

assert Solution().minValidStrings(words = ["xy","xyz","xyza","xyzab","xyzabc"], target = "xyzabcxyzabcxyzabcxyzabcxyzabc") == 5

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaa") == 4

assert Solution().minValidStrings(words = ["mnopqr","nopqr","opqr","pqr","qr","r"], target = "mnopqrnopqr") == 2

assert Solution().minValidStrings(words = ["ab","bc","cd","de","ef"], target = "abcdefabcdefabcdef") == 9

assert Solution().minValidStrings(words = ["quick", "brown", "fox", "jumps"], target = "quickbrownfoxjumpsquick") == 5

assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

assert Solution().minValidStrings(words = ["x", "xy", "xyz", "xyza"], target = "xyza") == 1

assert Solution().minValidStrings(words = ["abcd","abcde","abcdef"], target = "abcdefabcdefabcdef") == 3

assert Solution().minValidStrings(words = ["quick", "brown", "fox", "jumps", "over"], target = "quickbrownfoxjumpsoverquick") == 6

assert Solution().minValidStrings(words = ["xyz","xyzz","zzzz","zzzzy","zzzzz"], target = "xyzzzzzzzzzzzzzy") == 4

assert Solution().minValidStrings(words = ["prefix", "pre", "fix", "suffix"], target = "prefixsuffix") == 2

assert Solution().minValidStrings(words = ["abc","abcabc","abcabcabc"], target = "abcabcabcabcabcabc") == 2

assert Solution().minValidStrings(words = ["x","xy","xyz","xyza","xyzab"], target = "xyzabxyzabxyzab") == 3

assert Solution().minValidStrings(words = ["pqr","pqrs","pqrs","pqrstu","pqrstuv"], target = "pqrstuvpqrstuvpqrstuvpqrstuvpqrstu") == 5

assert Solution().minValidStrings(words = ["one","two","three","four","five"], target = "onetwothreefourfivetwothreefourfivefourfive") == 11

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcdeabcdeabcdeabcdeabcde") == 25

assert Solution().minValidStrings(words = ["abcd", "ab", "a"], target = "abcdabcdabcdabcd") == 4

assert Solution().minValidStrings(words = ["abcdefg", "hijklmn", "opqrstu", "vwxyz"], target = "abcdefghijklmnopqrstuvwxyzzzz") == -1

assert Solution().minValidStrings(words = ["unique", "words", "only"], target = "uniquewordsonly") == 3

assert Solution().minValidStrings(words = ["abcdefg", "abcdefgh", "abcdefghi"], target = "abcdefghiabcdefghiabcdefghi") == 3

assert Solution().minValidStrings(words = ["abc", "bcd", "cde", "def"], target = "abcdefabcdef") == 4

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e", "f", "g"], target = "abcdefg") == 7

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno","pqr","stu","vwx","yz"], target = "mnopqrstuvwx") == 4

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno","pqr"], target = "abcdefghijklmnopqr") == 6

assert Solution().minValidStrings(words = ["overlap","lap","laplap","aplap"], target = "overlaplaplaplaplap") == 3

assert Solution().minValidStrings(words = ["abcdef","bcdefg","cdefgh","defghi","efghij","fghijk"], target = "abcdefbcdefgcdefghdefghiefghijfghijk") == 6

assert Solution().minValidStrings(words = ["prefix","suffix","pre","suf"], target = "prefixsuffixprefixsuffix") == 4

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e", "f"], target = "fedcbafedcba") == 12

assert Solution().minValidStrings(words = ["abc", "def", "ghi", "jkl"], target = "abcdefghijkla") == 5

assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyxzyx") == -1

assert Solution().minValidStrings(words = ["one","two","three","four","five"], target = "onetwothreefourfive") == 5

assert Solution().minValidStrings(words = ["one","onetwo","onetwothree"], target = "onetwothreeonetwothreeonetwothree") == 3

assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j"], target = "abcdefghijabcdefghijabcdefghij") == 30

assert Solution().minValidStrings(words = ["abababab","bababa","ab","ba","a","b"], target = "ababababababababab") == 3

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaa","aaaaaaaa","aaaaaaaaa","aaaaaaaaaa"], target = "aaaaaaaaaaaaaaaaaaa") == 2

assert Solution().minValidStrings(words = ["aaaa", "aaaaa", "aaaaaa"], target = "aaaaaaaaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["hello","hell","he","h"], target = "hellohello") == 2

assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["z","zz","zzz","zzzz"], target = "zzzzzzzzzzzzzzzzzzzz") == 5

assert Solution().minValidStrings(words = ["overlap", "over", "lap", "laplap"], target = "overlaplaplap") == 2

assert Solution().minValidStrings(words = ["abc","bcd","cde"], target = "abcbcdcdedef") == -1

assert Solution().minValidStrings(words = ["abcdefg","abcdefgh","abcdefghi"], target = "abcdefghiabcdefghiabcdefghi") == 3

assert Solution().minValidStrings(words = ["aabbcc", "bbccdd", "ccddeeff"], target = "aabbccddeeff") == 2

assert Solution().minValidStrings(words = ["hello", "world", "hi"], target = "helloworld") == 2

assert Solution().minValidStrings(words = ["short", "longstringthatgoesonand", "onand", "and"], target = "longstringthatgoesonandonandonand") == 3

assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzxyzz") == -1

assert Solution().minValidStrings(words = ["aaa","aab","aac","aba","abb","abc"], target = "aabacbaabbac") == -1

assert Solution().minValidStrings(words = ["aabbcc", "bbccdd", "ccddeeff"], target = "aabbccbbccddeeffccddeeff") == 4

assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaa") == 7

assert Solution().minValidStrings(words = ["x","y","z"], target = "xyzxyzxyzxyzxyz") == 15

assert Solution().minValidStrings(words = ["word", "wordword", "wordwordword"], target = "wordwordwordwordwordwordwordwordwordword") == 4

assert Solution().minValidStrings(words = ["aabb","bbaa","abab"], target = "aabbaabbaabbabab") == 4

assert Solution().minValidStrings(words = ["longwordprefix","prefix","word","prefixword"], target = "longwordprefixprefixwordprefixwordprefix") == 4

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcdeabcdeabcde") == 15

assert Solution().minValidStrings(words = ["pqrst","pqrstu","pqrstuv"], target = "pqrstpqrstu") == 2

assert Solution().minValidStrings(words = ["ab", "bc", "cd"], target = "abcdabcdabcd") == 6

assert Solution().minValidStrings(words = ["abc", "bcd", "cde", "def", "efg"], target = "abcdefg") == 3

assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaaaaaaaaaaaaaaaa") == 7

assert Solution().minValidStrings(words = ["abc","ab","a"], target = "ababababab") == 5

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno"], target = "abcdefghijklmno") == 5

assert Solution().minValidStrings(words = ["aaa", "aa", "a"], target = "aaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["abcd", "abcde", "abcdef"], target = "abcdefabcdef") == 2

assert Solution().minValidStrings(words = ["abc", "abcd", "abcde"], target = "abcdeabcdabc") == 3

assert Solution().minValidStrings(words = ["abcabcabcabcabcabcabcabcabcabc"], target = "abcabcabcabcabcabcabcabcabcabc") == 1

assert Solution().minValidStrings(words = ["aaa", "bbb", "ccc"], target = "aaabbbccc") == 3

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"], target = "abcdefghijabcdefghij") == 20

assert Solution().minValidStrings(words = ["complex", "complexity", "complexities", "complexitytest"], target = "complexcomplexitycomplexitiescomplexitytest") == 4

assert Solution().minValidStrings(words = ["abcd","dcba","ab","ba","abc","cba","abcdcba","bacd"], target = "abcdabcbaabcd") == 4

assert Solution().minValidStrings(words = ["abc", "bcd", "cde"], target = "abcdexyz") == -1

assert Solution().minValidStrings(words = ["overlap", "laplap", "lap"], target = "overlapproverlap") == -1

assert Solution().minValidStrings(words = ["one", "two", "three"], target = "onetwothreeonetwothreeone") == 7

assert Solution().minValidStrings(words = ["abcd","ab","c","d"], target = "ababcdabcd") == 3

assert Solution().minValidStrings(words = ["abc", "abc", "abc"], target = "abcabcabc") == 3

assert Solution().minValidStrings(words = ["abc","abcabcabc","bcdef","ghijkl"], target = "abcabcabcghijkl") == 2

assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["ab","abc","abcd","abcde"], target = "abcdeabcdeabcde") == 3

assert Solution().minValidStrings(words = ["abcdef","abcde","abcd","abc","ab","a"], target = "abcdef") == 1

assert Solution().minValidStrings(words = ["aaa", "aaaa", "aaaaa"], target = "aaaaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["quick","brown","fox","jumps","over","lazy","dog"], target = "quickbrownfoxjumpsoverlazydog") == 7

assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyzyzyzy") == -1

assert Solution().minValidStrings(words = ["abc","bcd","cde","def"], target = "abcdeabcdef") == 4

assert Solution().minValidStrings(words = ["abcd","abcde","abcdef","abcdefg"], target = "abcdefgabcdefg") == 2

assert Solution().minValidStrings(words = ["abc", "abcd", "abcde"], target = "abcdeabcde") == 2

assert Solution().minValidStrings(words = ["ab", "cde", "fgh"], target = "abcdefg") == 3

assert Solution().minValidStrings(words = ["abc","acb","bac","bca","cab","cba"], target = "abcacbac") == 3

assert Solution().minValidStrings(words = ["abc","ab","a"], target = "abaababababababab") == 9

assert Solution().minValidStrings(words = ["test", "testing", "testcase", "case"], target = "testtestingtestcasetestcase") == 4

assert Solution().minValidStrings(words = ["one", "two", "three"], target = "onetwothreeonetwothree") == 6

assert Solution().minValidStrings(words = ["z","zz","zzz","zzzz"], target = "zzzzzzzzzzzzzzzzzz") == 5

assert Solution().minValidStrings(words = ["a", "ab", "abc", "abcd", "abcde"], target = "abcdeabcdeabcde") == 3

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa"], target = "aaaaaaaaaa") == 3

assert Solution().minValidStrings(words = ["aaaa","bbbb","cccc","dddd","eeee"], target = "abcdedcba") == 9

assert Solution().minValidStrings(words = ["longprefix","short","prefix","longerprefix","evenlongerprefix"], target = "longprefixlongerprefixevenlongerprefix") == 3

assert Solution().minValidStrings(words = ["prefix", "suffix", "infix", "prefixsuffix", "suffixprefix"], target = "prefixsuffixsuffixprefixprefix") == 3

assert Solution().minValidStrings(words = ["abcd","bcd","cd","d"], target = "abcdabcdabcdabcd") == 4

assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno","pqr","stu","vwx","yz","abcdefghijklmnopqrstuvwxyz"], target = "abcdefghijklmnopqrstuvwxyz") == 1

assert Solution().minValidStrings(words = ["same", "same", "same"], target = "samethatsame") == -1

assert Solution().minValidStrings(words = ["small", "smal", "sma", "sm"], target = "smallsmallsmallsmall") == 4

assert Solution().minValidStrings(words = ["abc","abcd","abcde","abcdef"], target = "abcdefabcdefabcdef") == 3

assert Solution().minValidStrings(words = ["xyz","abc","def"], target = "xyzabcxyzdef") == 4

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa"], target = "aaaaaaaa") == 2

assert Solution().minValidStrings(words = ["a", "ab", "abc", "abcd"], target = "abcdabcd") == 2

assert Solution().minValidStrings(words = ["hello", "world", "helloworld"], target = "helloworldhelloworld") == 2

assert Solution().minValidStrings(words = ["aabb","bbcc","ccdd","aabbcc","bbccdd"], target = "aabbccdd") == 2

assert Solution().minValidStrings(words = ["xy","yz","xyz","zxy","zyx"], target = "xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") == 11

assert Solution().minValidStrings(words = ["abc","abcd","abcde","abcdef"], target = "abcdefabcdef") == 2

assert Solution().minValidStrings(words = ["aaa", "aa", "a"], target = "aaaaaaaaaa") == 4

assert Solution().minValidStrings(words = ["abcd", "bcde", "cdef", "defg"], target = "abcdabcdabcdabcd") == 4

assert Solution().minValidStrings(words = ["abc", "abcabc", "abcabcabc"], target = "abcabcabcabcabc") == 2

assert Solution().minValidStrings(words = ["one", "two", "three", "four", "five"], target = "onetwothreefourfiveonetwothreefourfive") == 10

assert Solution().minValidStrings(words = ["longword", "longwo", "longw", "long"], target = "longwordlongwordlongword") == 3

assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j"], target = "abcdefghij") == 10

assert Solution().minValidStrings(words = ["longword", "another", "short"], target = "longwordanotherlongword") == 3

assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcde") == 5

assert Solution().minValidStrings(words = ["abcdef","ghijkl","mnopqr","stuvwx","yz","abc","def","ghi","jkl","mno","pqr","stu","vwx","yz"], target = "abcdefghijklmnopqrstuvwxyzyzyz") == 7

assert Solution().minValidStrings(words = ["abcdef", "defghi", "ghijkl"], target = "abcdefghijkl") == 2

assert Solution().minValidStrings(words = ["xyz", "yz", "z"], target = "xyzxyzxyzxyz") == 4

assert Solution().minValidStrings(words = ["prefix", "suffix"], target = "prefixprefixsuffix") == 3

assert Solution().minValidStrings(words = ["hello","world","hell","worl"], target = "helloworld") == 2

assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzyxyzyx") == -1

assert Solution().minValidStrings(words = ["prefix", "pre", "fix", "word"], target = "prefixprefixfix") == 3

assert Solution().minValidStrings(words = ["abcdef", "defgh", "efghi"], target = "abcdefghigfedcba") == -1

assert Solution().minValidStrings(words = ["abcde","bcde","cde","de","e"], target = "abcdebcdecde") == 3

assert Solution().minValidStrings(words = ["short","shor","sh","s"], target = "shortshortshortshortshort") == 5

assert Solution().minValidStrings(words = ["prefix","pre","fix","fi","ix"], target = "prefixprefix") == 2

assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

assert Solution().minValidStrings(words = ["abc","abcd","abce"], target = "abcdeabcde") == -1

assert Solution().minValidStrings(words = ["abcabc", "abc", "ab"], target = "abcabcabcabc") == 2

assert Solution().minValidStrings(words = ["repeated", "repeate", "repeat", "repe", "rep", "re", "r"], target = "repeatedrepeatedrepeatedrepeated") == 4

assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaaaaaa") == 4

assert Solution().minValidStrings(words = ["prefix", "prefi", "pref", "pre"], target = "prefixprefiprefpre") == 4

Answer: assert Solution().minValidStrings(words = ["abc"], target = "abcabc") == 2

Answer: assert Solution().minValidStrings(words = ["a"], target = "a") == 1

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["xyz"], target = "xyz") == 1

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa"], target = "aaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["a"], target = "aaaaaaaaaa") == 10

Answer: assert Solution().minValidStrings(words = ["abababab","ab"], target = "ababaababa") == 2

Answer: assert Solution().minValidStrings(words = ["abcde"], target = "abcde") == 1

Answer: assert Solution().minValidStrings(words = ["abc","aaaaa","bcdef"], target = "aabcdabc") == 3

Answer: assert Solution().minValidStrings(words = ["hello","world"], target = "hello") == 1

Answer: assert Solution().minValidStrings(words = ["abcd", "efgh", "ijkl"], target = "abcdefghij") == 3

Answer: assert Solution().minValidStrings(words = ["abcdef"], target = "xyz") == -1

Answer: assert Solution().minValidStrings(words = ["abc","abc","abc"], target = "abcabc") == 2

Answer: assert Solution().minValidStrings(words = ["z", "y", "x"], target = "zyxzyxzyx") == 9

Answer: assert Solution().minValidStrings(words = ["abcdef", "ghijkl"], target = "abcdefghijkl") == 2

Answer: assert Solution().minValidStrings(words = ["abc", "def", "ghi"], target = "abcdefghi") == 3

Answer: assert Solution().minValidStrings(words = ["hello","world"], target = "helloworld") == 2

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi"], target = "abcdef") == 2

Answer: assert Solution().minValidStrings(words = ["a","b","c"], target = "abc") == 3

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl"], target = "abcdefghijklop") == -1

Answer: assert Solution().minValidStrings(words = ["z"], target = "zzzzz") == 5

Answer: assert Solution().minValidStrings(words = ["abcd","efgh","ijkl"], target = "abcdefghijklijkl") == 4

Answer: assert Solution().minValidStrings(words = ["hello","helloo","hellooo","helloooo"], target = "helloooohelloooohelloooohelloooo") == 4

Answer: assert Solution().minValidStrings(words = ["mnop","mnopqr","mnopqrst","mnopqrstu","mnopqrstuv"], target = "mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstu") == 4

Answer: assert Solution().minValidStrings(words = ["z", "zz", "zzz", "zzzz", "zzzzz"], target = "zzzzzzzzzzzzzz") == 3

Answer: assert Solution().minValidStrings(words = ["zzzzz","zzzz","zzz","zz","z"], target = "zzzzzzzzzzzzzzzzzzzzzz") == 5

Answer: assert Solution().minValidStrings(words = ["hello","world","hel","wor"], target = "helloworldhelloworld") == 4

Answer: assert Solution().minValidStrings(words = ["abcd", "bcde", "cdef", "defg"], target = "abcdefghijklmnop") == -1

Answer: assert Solution().minValidStrings(words = ["abcdef","bcdef","cdef","def","ef","f"], target = "abcdefbcdefcdef") == 3

Answer: assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzxyxyxzyzyx") == -1

Answer: assert Solution().minValidStrings(words = ["start", "startstart", "startstartstart"], target = "startstartstart") == 1

Answer: assert Solution().minValidStrings(words = ["example", "sample", "exam", "ple", "samplesample"], target = "examplesamplesampleple") == 3

Answer: assert Solution().minValidStrings(words = ["z", "zy", "zyx", "zyxw"], target = "zyxwzyxwzyxwzyxw") == 4

Answer: assert Solution().minValidStrings(words = ["abcdef","fedcba","abc","cba","def","efd"], target = "abcdefcbaefdefabc") == 5

Answer: assert Solution().minValidStrings(words = ["abcd", "efgh", "ijkl"], target = "abcdefghijklijk") == 4

Answer: assert Solution().minValidStrings(words = ["aabbcc","bbaacc","ccaabb","aabbbccc","abbcccaab"], target = "aabbccbbcccaababbcccaab") == 5

Answer: assert Solution().minValidStrings(words = ["xy","xyz","xyza","xyzab","xyzabc"], target = "xyzabcxyzabcxyzabcxyzabcxyzabc") == 5

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaa") == 4

Answer: assert Solution().minValidStrings(words = ["mnopqr","nopqr","opqr","pqr","qr","r"], target = "mnopqrnopqr") == 2

Answer: assert Solution().minValidStrings(words = ["ab","bc","cd","de","ef"], target = "abcdefabcdefabcdef") == 9

Answer: assert Solution().minValidStrings(words = ["quick", "brown", "fox", "jumps"], target = "quickbrownfoxjumpsquick") == 5

Answer: assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

Answer: assert Solution().minValidStrings(words = ["x", "xy", "xyz", "xyza"], target = "xyza") == 1

Answer: assert Solution().minValidStrings(words = ["abcd","abcde","abcdef"], target = "abcdefabcdefabcdef") == 3

Answer: assert Solution().minValidStrings(words = ["quick", "brown", "fox", "jumps", "over"], target = "quickbrownfoxjumpsoverquick") == 6

Answer: assert Solution().minValidStrings(words = ["xyz","xyzz","zzzz","zzzzy","zzzzz"], target = "xyzzzzzzzzzzzzzy") == 4

Answer: assert Solution().minValidStrings(words = ["prefix", "pre", "fix", "suffix"], target = "prefixsuffix") == 2

Answer: assert Solution().minValidStrings(words = ["abc","abcabc","abcabcabc"], target = "abcabcabcabcabcabc") == 2

Answer: assert Solution().minValidStrings(words = ["x","xy","xyz","xyza","xyzab"], target = "xyzabxyzabxyzab") == 3

Answer: assert Solution().minValidStrings(words = ["pqr","pqrs","pqrs","pqrstu","pqrstuv"], target = "pqrstuvpqrstuvpqrstuvpqrstuvpqrstu") == 5

Answer: assert Solution().minValidStrings(words = ["one","two","three","four","five"], target = "onetwothreefourfivetwothreefourfivefourfive") == 11

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcdeabcdeabcdeabcdeabcde") == 25

Answer: assert Solution().minValidStrings(words = ["abcd", "ab", "a"], target = "abcdabcdabcdabcd") == 4

Answer: assert Solution().minValidStrings(words = ["abcdefg", "hijklmn", "opqrstu", "vwxyz"], target = "abcdefghijklmnopqrstuvwxyzzzz") == -1

Answer: assert Solution().minValidStrings(words = ["unique", "words", "only"], target = "uniquewordsonly") == 3

Answer: assert Solution().minValidStrings(words = ["abcdefg", "abcdefgh", "abcdefghi"], target = "abcdefghiabcdefghiabcdefghi") == 3

Answer: assert Solution().minValidStrings(words = ["abc", "bcd", "cde", "def"], target = "abcdefabcdef") == 4

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e", "f", "g"], target = "abcdefg") == 7

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno","pqr","stu","vwx","yz"], target = "mnopqrstuvwx") == 4

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno","pqr"], target = "abcdefghijklmnopqr") == 6

Answer: assert Solution().minValidStrings(words = ["overlap","lap","laplap","aplap"], target = "overlaplaplaplaplap") == 3

Answer: assert Solution().minValidStrings(words = ["abcdef","bcdefg","cdefgh","defghi","efghij","fghijk"], target = "abcdefbcdefgcdefghdefghiefghijfghijk") == 6

Answer: assert Solution().minValidStrings(words = ["prefix","suffix","pre","suf"], target = "prefixsuffixprefixsuffix") == 4

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e", "f"], target = "fedcbafedcba") == 12

Answer: assert Solution().minValidStrings(words = ["abc", "def", "ghi", "jkl"], target = "abcdefghijkla") == 5

Answer: assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyxzyx") == -1

Answer: assert Solution().minValidStrings(words = ["one","two","three","four","five"], target = "onetwothreefourfive") == 5

Answer: assert Solution().minValidStrings(words = ["one","onetwo","onetwothree"], target = "onetwothreeonetwothreeonetwothree") == 3

Answer: assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j"], target = "abcdefghijabcdefghijabcdefghij") == 30

Answer: assert Solution().minValidStrings(words = ["abababab","bababa","ab","ba","a","b"], target = "ababababababababab") == 3

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaa","aaaaaaaa","aaaaaaaaa","aaaaaaaaaa"], target = "aaaaaaaaaaaaaaaaaaa") == 2

Answer: assert Solution().minValidStrings(words = ["aaaa", "aaaaa", "aaaaaa"], target = "aaaaaaaaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["hello","hell","he","h"], target = "hellohello") == 2

Answer: assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["z","zz","zzz","zzzz"], target = "zzzzzzzzzzzzzzzzzzzz") == 5

Answer: assert Solution().minValidStrings(words = ["overlap", "over", "lap", "laplap"], target = "overlaplaplap") == 2

Answer: assert Solution().minValidStrings(words = ["abc","bcd","cde"], target = "abcbcdcdedef") == -1

Answer: assert Solution().minValidStrings(words = ["abcdefg","abcdefgh","abcdefghi"], target = "abcdefghiabcdefghiabcdefghi") == 3

Answer: assert Solution().minValidStrings(words = ["aabbcc", "bbccdd", "ccddeeff"], target = "aabbccddeeff") == 2

Answer: assert Solution().minValidStrings(words = ["hello", "world", "hi"], target = "helloworld") == 2

Answer: assert Solution().minValidStrings(words = ["short", "longstringthatgoesonand", "onand", "and"], target = "longstringthatgoesonandonandonand") == 3

Answer: assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzxyzz") == -1

Answer: assert Solution().minValidStrings(words = ["aaa","aab","aac","aba","abb","abc"], target = "aabacbaabbac") == -1

Answer: assert Solution().minValidStrings(words = ["aabbcc", "bbccdd", "ccddeeff"], target = "aabbccbbccddeeffccddeeff") == 4

Answer: assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaa") == 7

Answer: assert Solution().minValidStrings(words = ["x","y","z"], target = "xyzxyzxyzxyzxyz") == 15

Answer: assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"], target = "abcdefghijklmnopqrstuvwxyz") == 26

Answer: assert Solution().minValidStrings(words = ["word", "wordword", "wordwordword"], target = "wordwordwordwordwordwordwordwordwordword") == 4

Answer: assert Solution().minValidStrings(words = ["aabb","bbaa","abab"], target = "aabbaabbaabbabab") == 4

Answer: assert Solution().minValidStrings(words = ["longwordprefix","prefix","word","prefixword"], target = "longwordprefixprefixwordprefixwordprefix") == 4

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcdeabcdeabcde") == 15

Answer: assert Solution().minValidStrings(words = ["pqrst","pqrstu","pqrstuv"], target = "pqrstpqrstu") == 2

Answer: assert Solution().minValidStrings(words = ["ab", "bc", "cd"], target = "abcdabcdabcd") == 6

Answer: assert Solution().minValidStrings(words = ["abc", "bcd", "cde", "def", "efg"], target = "abcdefg") == 3

Answer: assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaaaaaaaaaaaaaaaa") == 7

Answer: assert Solution().minValidStrings(words = ["abc","ab","a"], target = "ababababab") == 5

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno"], target = "abcdefghijklmno") == 5

Answer: assert Solution().minValidStrings(words = ["aaa", "aa", "a"], target = "aaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["abcd", "abcde", "abcdef"], target = "abcdefabcdef") == 2

Answer: assert Solution().minValidStrings(words = ["abc", "abcd", "abcde"], target = "abcdeabcdabc") == 3

Answer: assert Solution().minValidStrings(words = ["abcabcabcabcabcabcabcabcabcabc"], target = "abcabcabcabcabcabcabcabcabcabc") == 1

Answer: assert Solution().minValidStrings(words = ["aaa", "bbb", "ccc"], target = "aaabbbccc") == 3

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"], target = "abcdefghijabcdefghij") == 20

Answer: assert Solution().minValidStrings(words = ["complex", "complexity", "complexities", "complexitytest"], target = "complexcomplexitycomplexitiescomplexitytest") == 4

Answer: assert Solution().minValidStrings(words = ["abcd","dcba","ab","ba","abc","cba","abcdcba","bacd"], target = "abcdabcbaabcd") == 4

Answer: assert Solution().minValidStrings(words = ["abc", "bcd", "cde"], target = "abcdexyz") == -1

Answer: assert Solution().minValidStrings(words = ["overlap", "laplap", "lap"], target = "overlapproverlap") == -1

Answer: assert Solution().minValidStrings(words = ["one", "two", "three"], target = "onetwothreeonetwothreeone") == 7

Answer: assert Solution().minValidStrings(words = ["abcd","ab","c","d"], target = "ababcdabcd") == 3

Answer: assert Solution().minValidStrings(words = ["abc", "abc", "abc"], target = "abcabcabc") == 3

Answer: assert Solution().minValidStrings(words = ["abc","abcabcabc","bcdef","ghijkl"], target = "abcabcabcghijkl") == 2

Answer: assert Solution().minValidStrings(words = ["a", "aa", "aaa", "aaaa"], target = "aaaaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["ab","abc","abcd","abcde"], target = "abcdeabcdeabcde") == 3

Answer: assert Solution().minValidStrings(words = ["abcdef","abcde","abcd","abc","ab","a"], target = "abcdef") == 1

Answer: assert Solution().minValidStrings(words = ["aaa", "aaaa", "aaaaa"], target = "aaaaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["quick","brown","fox","jumps","over","lazy","dog"], target = "quickbrownfoxjumpsoverlazydog") == 7

Answer: assert Solution().minValidStrings(words = ["xyz","xy","x"], target = "xyzyzyzyzy") == -1

Answer: assert Solution().minValidStrings(words = ["abc","bcd","cde","def"], target = "abcdeabcdef") == 4

Answer: assert Solution().minValidStrings(words = ["abcd","abcde","abcdef","abcdefg"], target = "abcdefgabcdefg") == 2

Answer: assert Solution().minValidStrings(words = ["abc", "abcd", "abcde"], target = "abcdeabcde") == 2

Answer: assert Solution().minValidStrings(words = ["ab", "cde", "fgh"], target = "abcdefg") == 3

Answer: assert Solution().minValidStrings(words = ["abc","acb","bac","bca","cab","cba"], target = "abcacbac") == 3

Answer: assert Solution().minValidStrings(words = ["abc","ab","a"], target = "abaababababababab") == 9

Answer: assert Solution().minValidStrings(words = ["test", "testing", "testcase", "case"], target = "testtestingtestcasetestcase") == 4

Answer: assert Solution().minValidStrings(words = ["one", "two", "three"], target = "onetwothreeonetwothree") == 6

Answer: assert Solution().minValidStrings(words = ["z","zz","zzz","zzzz"], target = "zzzzzzzzzzzzzzzzzz") == 5

Answer: assert Solution().minValidStrings(words = ["a", "ab", "abc", "abcd", "abcde"], target = "abcdeabcdeabcde") == 3

Answer: assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"], target = "zzzzzzzzzz") == 10

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa"], target = "aaaaaaaaaa") == 3

Answer: assert Solution().minValidStrings(words = ["aaaa","bbbb","cccc","dddd","eeee"], target = "abcdedcba") == 9

Answer: assert Solution().minValidStrings(words = ["longprefix","short","prefix","longerprefix","evenlongerprefix"], target = "longprefixlongerprefixevenlongerprefix") == 3

Answer: assert Solution().minValidStrings(words = ["prefix", "suffix", "infix", "prefixsuffix", "suffixprefix"], target = "prefixsuffixsuffixprefixprefix") == 3

Answer: assert Solution().minValidStrings(words = ["abcd","bcd","cd","d"], target = "abcdabcdabcdabcd") == 4

Answer: assert Solution().minValidStrings(words = ["abc","def","ghi","jkl","mno","pqr","stu","vwx","yz","abcdefghijklmnopqrstuvwxyz"], target = "abcdefghijklmnopqrstuvwxyz") == 1

Answer: assert Solution().minValidStrings(words = ["same", "same", "same"], target = "samethatsame") == -1

Answer: assert Solution().minValidStrings(words = ["small", "smal", "sma", "sm"], target = "smallsmallsmallsmall") == 4

Answer: assert Solution().minValidStrings(words = ["abc","abcd","abcde","abcdef"], target = "abcdefabcdefabcdef") == 3

Answer: assert Solution().minValidStrings(words = ["xyz","abc","def"], target = "xyzabcxyzdef") == 4

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa"], target = "aaaaaaaa") == 2

Answer: assert Solution().minValidStrings(words = ["a", "ab", "abc", "abcd"], target = "abcdabcd") == 2

Answer: assert Solution().minValidStrings(words = ["hello", "world", "helloworld"], target = "helloworldhelloworld") == 2

Answer: assert Solution().minValidStrings(words = ["aabb","bbcc","ccdd","aabbcc","bbccdd"], target = "aabbccdd") == 2

Answer: assert Solution().minValidStrings(words = ["xy","yz","xyz","zxy","zyx"], target = "xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz") == 11

Answer: assert Solution().minValidStrings(words = ["abc","abcd","abcde","abcdef"], target = "abcdefabcdef") == 2

Answer: assert Solution().minValidStrings(words = ["aaa", "aa", "a"], target = "aaaaaaaaaa") == 4

Answer: assert Solution().minValidStrings(words = ["abcd", "bcde", "cdef", "defg"], target = "abcdabcdabcdabcd") == 4

Answer: assert Solution().minValidStrings(words = ["abc", "abcabc", "abcabcabc"], target = "abcabcabcabcabc") == 2

Answer: assert Solution().minValidStrings(words = ["one", "two", "three", "four", "five"], target = "onetwothreefourfiveonetwothreefourfive") == 10

Answer: assert Solution().minValidStrings(words = ["longword", "longwo", "longw", "long"], target = "longwordlongwordlongword") == 3

Answer: assert Solution().minValidStrings(words = ["a","b","c","d","e","f","g","h","i","j"], target = "abcdefghij") == 10

Answer: assert Solution().minValidStrings(words = ["longword", "another", "short"], target = "longwordanotherlongword") == 3

Answer: assert Solution().minValidStrings(words = ["a", "b", "c", "d", "e"], target = "abcde") == 5

Answer: assert Solution().minValidStrings(words = ["abcdef","ghijkl","mnopqr","stuvwx","yz","abc","def","ghi","jkl","mno","pqr","stu","vwx","yz"], target = "abcdefghijklmnopqrstuvwxyzyzyz") == 7

Answer: assert Solution().minValidStrings(words = ["abcdef", "defghi", "ghijkl"], target = "abcdefghijkl") == 2

Answer: assert Solution().minValidStrings(words = ["xyz", "yz", "z"], target = "xyzxyzxyzxyz") == 4

Answer: assert Solution().minValidStrings(words = ["prefix", "suffix"], target = "prefixprefixsuffix") == 3

Answer: assert Solution().minValidStrings(words = ["hello","world","hell","worl"], target = "helloworld") == 2

Answer: assert Solution().minValidStrings(words = ["xyz", "xy", "x"], target = "xyzyxyzyx") == -1

Answer: assert Solution().minValidStrings(words = ["prefix", "pre", "fix", "word"], target = "prefixprefixfix") == 3

Answer: assert Solution().minValidStrings(words = ["abcdef", "defgh", "efghi"], target = "abcdefghigfedcba") == -1

Answer: assert Solution().minValidStrings(words = ["abcde","bcde","cde","de","e"], target = "abcdebcdecde") == 3

Answer: assert Solution().minValidStrings(words = ["short","shor","sh","s"], target = "shortshortshortshortshort") == 5

Answer: assert Solution().minValidStrings(words = ["prefix","pre","fix","fi","ix"], target = "prefixprefix") == 2

Answer: assert Solution().minValidStrings(words = ["a","aa","aaa","aaaa","aaaaa"], target = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") == 8

Answer: assert Solution().minValidStrings(words = ["abc","abcd","abce"], target = "abcdeabcde") == -1

Answer: assert Solution().minValidStrings(words = ["abcabc", "abc", "ab"], target = "abcabcabcabc") == 2

Answer: assert Solution().minValidStrings(words = ["repeated", "repeate", "repeat", "repe", "rep", "re", "r"], target = "repeatedrepeatedrepeatedrepeated") == 4

Answer: assert Solution().minValidStrings(words = ["aaa","aa","a"], target = "aaaaaaaaaa") == 4

Answer: assert Solution().minValidStrings(words = ["prefix", "prefi", "pref", "pre"], target = "prefixprefiprefpre") == 4

import random
import functools
import collections
import string
import math
import datetime

from typing import *
from functools import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from string import *
from operator import *
from math import *

inf = float('inf')

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def list_node(values: list):
    if not values:
        return None
    head = ListNode(values[0])
    p = head
    for val in values[1:]:
        node = ListNode(val)
        p.next = node
        p = node
    return head

def is_same_list(p1, p2):
    if p1 is None and p2 is None:
        return True
    if not p1 or not p2:
        return False
    return p1.val == p2.val and is_same_list(p1.next, p2.next)

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def tree_node(values: list):
    if not values:
        return None
    root = TreeNode(values[0])
    i = 1
    queue = deque()
    queue.append(root)
    while queue:
        node = queue.popleft()
        if i < len(values) and values[i] is not None:
            node.left = TreeNode(values[i])
            queue.append(node.left)
        i += 1
        if i < len(values) and values[i] is not None:
            node.right = TreeNode(values[i])
            queue.append(node.right)
        i += 1
    return root

def is_same_tree(p, q):
    if not p and not q:
        return True
    elif not p or not q:
        return False
    elif p.val != q.val:
        return False
    else:
        return is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right)

class Hashing:
    __slots__ = ["mod", "h", "p"]

    def __init__(self, s: List[str], base: int, mod: int):
        self.mod = mod
        self.h = [0] * (len(s) + 1)
        self.p = [1] * (len(s) + 1)
        for i in range(1, len(s) + 1):
            self.h[i] = (self.h[i - 1] * base + ord(s[i - 1])) % mod
            self.p[i] = (self.p[i - 1] * base) % mod

    def query(self, l: int, r: int) -> int:
        return (self.h[r] - self.h[l - 1] * self.p[r - l + 1]) % self.mod

class Solution:
    def minValidStrings(self, words: List[str], target: str) -> int:
        def f(i: int) -> int:
            l, r = 0, min(n - i, m)
            while l < r:
                mid = (l + r + 1) >> 1
                sub = hashing.query(i + 1, i + mid)
                if sub in s[mid]:
                    l = mid
                else:
                    r = mid - 1
            return l

        base, mod = 13331, 998244353
        hashing = Hashing(target, base, mod)
        m = max(len(w) for w in words)
        s = [set() for _ in range(m + 1)]
        for w in words:
            h = 0
            for j, c in enumerate(w, 1):
                h = (h * base + ord(c)) % mod
                s[j].add(h)
        ans = last = mx = 0
        n = len(target)
        for i in range(n):
            dist = f(i)
            mx = max(mx, i + dist)
            if i == last:
                if i == mx:
                    return -1
                last = mx
                ans += 1
        return ans