Minimum Number of Valid Strings to Form Target I
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.
Examples
Input: [["abc","aaaaa","bcdef"],"aabcdabc"]
Output: 3
Input: [["abababab","ab"],"ababaababa"]
Output: 2
Hints
Build a Trie from all words.
Use dynamic programming where `dp[i]` is the minimum number of valid strings to form `target[i:]`.
From each position, walk the Trie as far as `target` matches to find all valid-prefix lengths.
Related Problems
Minimum Number of Valid Strings to Form Target I
You are given an array of strings `words` and a string `target`.