Distinct Subsequences
Count subsequences of s whose characters spell t, counting distinct selected index sets separately.
Example 1
s = "babgbag"
t = "bag"5Explanation
Index triples (0,1,3), (0,1,6), (0,5,6), (2,5,6), (4,5,6) spell bag, giving five.
Example 2
s = "aaa"
t = "aa"3Explanation
Choose any two of three a positions, giving three index sets.
Example 3
s = "abc"
t = "d"0Explanation
No d occurs in the source, so no matching subsequence exists.
Example 4
s = "abc"
t = ""1Explanation
The empty target has one subsequence: select no source positions.
Constraints
- 0 <= len(s),len(t) <= 1000
- Strings contain English letters
- The answer fits a signed 32-bit integer
Function contract
numDistinctArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 36 cases, on your device.
"babgbag""bag"