#3292

Minimum Number of Valid Strings to Form Target II

grandmaster · 2200 · lc hard +32 · 20.4% accepted · 85 likes · top 2%

Description

You are given string array words and string target. A string is valid if it is a prefix of any word in words. Return the minimum number of valid strings concatenated to form target, or -1 if impossible.

Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity.

Code

1
2
3