String Formation (Also for AI/ML Software Engineer Intern :)
Given an array of strings, each of the same length, and a target string, construct the target string using characters from the strings in the given array in such a way that the indices of the characters used are in a strictly increasing sequence. Here, the index of a character is the position at which it appears in the string. Multiple characters can be used from the same string.
Determine the number of ways to construct the target string. Two constructions are considered different if either the sequences of indices they use are different or the sequences are the same but there exists a character at some index that is chosen from a different string. Return the value modulo (10^9 + 7).
Complete the function numWays in the editor below.
numWays has the following parameters:
- 1.
String words[n]: an array of strings - 2.
String target: the target string
Returns
int: an integer representing the number of ways, modulo (109 + 7)
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.