Given two strings S and T, find the number of times the second string occurs in the first string, whether continuous or discontinuous as subsequence
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
First, we discuss the recursive solution and then we will convert it to dynamic programming.
Prerequisite:
How, how can we generate a recursive relation?
Say,
Say,
Now we have to option,
Now we have only one option which is check for starts+1, startt as we need to look for different occurrence only.
The above recursion will generate many overlapping subproblems and hence we need to use dynamic programming. (I would recommend to take two short string and try doing by your hand and draw the recursion tree to understand how recursion is working).
Let's convert the recursion to DP.
C++ Implementation:
Output