Problem of the day
A Subsequence of a string is the string that is obtained by deleting 0 or more letters from the string and keeping the rest of the letters in the same order.
We are given two strings, 'str' and 'sub'.
Find the number of subsequences of 'str' which are equal to 'sub'.
Since the answer can be very large, print it modulo 10 ^ 9 + 7.
Input: 'str' = “brootgroot” and 'sub' = “brt”
Output: 3
Explanation: The following subsequences formed by characters at given indices (0-based) of 'str' are equal to 'sub' :
str[0] = ‘b’, str[1] = ‘r’, str[4] = ‘t’
str[0] = ‘b’, str[1] = ‘r’, str[9] = ‘t’
str[0] = ‘b’, str[6] = ‘r’, str[9] = ‘t’
The first line contains the string 'str', denoting the first string of the problem statement.
The second line contains the string 'sub', denoting the second string of the problem statement.
Print the number of subsequences of 'str' which are equal to 'sub' (modulo 1000000007).
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
brootgroot
brt
3
The following subsequences formed by characters at given indices (0-based) of 'str' are equal to 'sub' :
str[0] = ‘b’, str[1] = ‘r’, str[4] = ‘t’
str[0] = ‘b’, str[1] = ‘r’, str[9] = ‘t’
str[0] = ‘b’, str[6] = ‘r’, str[9] = ‘t’
dingdingdingding
ing
20
aaaaa
a
5
The expected time complexity is O(|str| * |sub|).
1 <= |str| <= 1000
1 <= |sub| <= 1000
Where |str| represents the length of the string 'str', and |sub| represents the length of the string 'sub'.
Time Limit: 1 sec.