hard2-D Dynamic ProgrammingFacebook
Subsequence Appearance Counter
A proofreader counts how many distinct ways a target word appears as a subsequence of a source text.
Given strings s and t, return the number of distinct subsequences of s which equal t.
Choose approach
1
?
?
?
?
?
?
1
1
0
0
0
0
0
row
1
?
?
?
?
?
?
1
?
?
?
?
?
?
1
?
?
?
?
?
?
1
?
?
?
?
?
?
1
?
?
?
?
?
?
1
?
?
?
?
?
?
1/8
Narrationstep 1 of 8
Row 1 filled using s[0] = 'r'.
Variables
i=1
How to think about it
- Second-level counting on top of LCS structure.
- Empty target column always 1 (empty subseq).
Edge cases to catch in interview
- t empty -> 1.
- |t| > |s| -> 0.
Examples
Example 1
5{"s":"babgbag","t":"bag"}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed