Given two strings text and target, return the number of distinct subsequences of text that equal target.
A subsequence is formed by deleting zero or more characters of a string without changing the relative order of the remaining characters (for example, "ace" is a subsequence of "abcde"). Two subsequences are distinct if they use a different set of positions of text.
The test cases are constructed so that the answer fits in a signed 32-bit integer.
Examples
Example 1
Input: text = "rabbbit", target = "rabbit"
Output: 3
Explanation: There are 3 ways to obtain "rabbit" from "rabbbit" by deleting one
of the three 'b' characters.
Example 2
Input: text = "babgbag", target = "bag"
Output: 5
Explanation: There are 5 distinct sets of positions in "babgbag" that spell
"bag".
Constraints
1≤text.length, target.length≤1000
text and target consist of English letters.
The answer fits in a signed 32-bit integer.
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up