Problem · Dynamic Programming
String Formation
Learn this problemProblem statement
All words have equal length. Form target by choosing its characters from strictly increasing column indices; at a chosen column, the character may come from any word. Count distinct index-and-word choices modulo 10^9 + 7.
Function
numWays(words: String[], target: String) → intExamples
Example 1
words = ["adc","aec","efg"]target = "ac"return = 4There are two choices for 'a' in column zero and two choices for 'c' in column two.
Constraints
1 <= words.length <= 10001 <= words[i].length <= 30001 <= target.length <= words[i].length- All characters are lowercase English letters.