Find number of times a string occurs as a subsequence in given string | Recursive function to find the number of times the second string occurs in the first string , whether continuous or discontinuous ; If both first and second string is empty , or if second string is empty , return 1 ; If only first string is empty and second string is not empty , return 0 ; If last characters are same Recur for remaining strings by 1. considering last characters of both strings 2. ignoring last character of first string ; If last characters are different , ignore last char of first string and recur for remaining string ; Driver code
def count ( a , b , m , n ) : NEW_LINE INDENT if ( ( m == 0 and n == 0 ) or n == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( m == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( a [ m - 1 ] == b [ n - 1 ] ) : NEW_LINE INDENT return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return count ( a , b , m - 1 , n ) NEW_LINE DEDENT DEDENT a = " GeeksforGeeks " NEW_LINE b = " Gks " NEW_LINE print ( count ( a , b , len ( a ) , len ( b ) ) ) NEW_LINE