RubrikOA #6
Longest Subsequence Matching a Substring
Estimated MediumJudge-ready
Topics (AI-labelled)String DPSubsequences
Given strings x and y, find the maximum length of a subsequence of x that is also a non-empty contiguous substring of y.
Input
Two lines with non-empty ASCII strings x and y; added by this site: |x|,|y|≤2000.
Output
Output the required length; if no non-empty match exists, output 0.
Example 1
Input:
abcd
abdc
Output:
3
Example 2
Input:
hackerranks
hackers
Output:
7
Example 3
Input:
abc
XYZ
Output:
0
Editorial
Loading solution…