P20790 [GeeksforGeeks] Find length of longest subsequence4905
普及
题目描述

Given two string X and Y of length N and M respectively. The task is to find the length of the longest subsequence of string X which is a substring in sequence Y.
Example 1:
Input:
N = 4, M = 8
X = "abcd"
Y = "bacdbdcd"
Output: 3
Explanation: "acd" is the longest subsequence
from string X present as a
substring in string Y.
Example 2:
Input:
N = 1, M = 1
X = 'a'
Y = 'a'
Output: 1
Explanation: 'a' is the answer.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSubsequenceSubstring() which takes 4 arguments(string X, string Y, N and M) and returns the answer.
Expected Time Complexity: O(NM).
Expected Auxiliary Space: O(N
M).
Constraints:
1<= N, M <=10^{3}

输入格式

见题面

输出格式

见题面

样例输入
N = 4, M = 8 X = "abcd" Y = "bacdbdcd"
样例输出
3