Classic example
Input
s = "rabbbit", t = "rabbit"
Output
3
There are three ways to delete one of the three consecutive 'b's to form 'rabbit'.
Full lesson preview
Compute how many distinct subsequences of a source string equal a target string using dynamic programming. This classic DP counts ways of choosing characters (not necessarily contiguous).
Problem statement
Task
Examples
Input
s = "rabbbit", t = "rabbit"
Output
3
There are three ways to delete one of the three consecutive 'b's to form 'rabbit'.
Input format
Output format
Constraints
Samples
Input
s = "abc", t = ""
Output
1
There is exactly one subsequence of any string equal to the empty string: delete all characters.