X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Substring - Subsequence problem
Medium Accuracy: 45.71% Submissions: 816 Points: 4

Find the longest subsequence X of a string A which is a substring Y of a string B.

Note: All letters of the Strings are Uppercased.

 

Example 1:

Input:
A = "ABCD" , B = "BACDBDCD"
Output:
3
Explanation:
The answer would be 3 as because "ACD"
is the longest subsequence of A which
is also a substring of B.

Example 2:

Input:
A = "A" , B = "A"
Output:
1
Explanation:
The answer would be 1 as because "A"
is the longest subsequence of A which
is also a substring of B. 

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function getLongestSubsequence() which takes Strings A  and B as input and returns the answer.

 

Expected Time Complexity: O(|S|2)
Expected Auxiliary Space: O(|S|2)

 

Constraints:
1 <= |A|,|B| <= 103

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


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.

Substring - Subsequence problem

Output Window