String Subsequence
Easy Accuracy: 56.18% Submissions: 708 Points: 2

Given two strings S1 and S2, find the number of times the second string occurs in the first string, whether continuous or discontinuous.


Example 1:

Input: 
S1 = geeksforgeeks
S2 = gks
Output: 4
Explaination: For the first 'g' there 
are 3 ways and for the second 'g' there 
is one way. Total 4 ways.


Your Task:
You don't need to read input or print anything. Your task is to complete the function countWays() which takes the string S1 and S2 as input parameters and returns the number of ways.


Expected Time Complexity: O(n*m)        [n and m are length of the strings]
Expected Auxiliary Space: O(n*m)


Constraints:
1 ≤ n, m ≤ 500

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window