Distinct Subsequences

Given two sequences S, T, count number of unique ways in sequence S, to form a subsequence that is identical to the sequence T.

Subsequence : A subsequence of a string is a new string which is formed from the original string by deleting some (can be none ) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).

Example :

S = "rabbbit" 
T = "rabbit"

Return 3. And the formations as follows:

S1= "ra_bbit" 
S2= "rab_bit" 

"_" marks the removed character.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Distinct Subsequences on Interview Code Editor
Sign Up
to access hints and editorial solutions for Distinct Subsequences
Asked In:
  • Google
Click here to start solving coding interview questions