Loading...
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.
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.
Input: text = "babgbag", target = "bag"
Output: 5
Explanation: There are 5 distinct sets of positions in "babgbag" that spell
"bag".
text.length, target.length ≤1000text and target consist of English letters.Click "Run" to test with sample cases or "Submit" to run all tests.