Problem · Dynamic Programming

Find Longest Subsequence Common to X as Substring in Y (MLE :)

HardSalesforceNEW GRADOA
See Salesforce hiring insights

Given two strings x and y, find the longest subsequence of x that is also a substring of y. Return the maximum length of such a subsequence.

Examples
01 · Example 1
x = "hackerranks"
y = "hackers"
return = 7
The entire string "hackers" is a substring of y and also a subsequence of x (characters appear in order). The maximum length is 7.
More Salesforce problems
drafts saved locally
public int findLongestSubsequenceCommonToXAsSubstringInY(String x, String y) {
  // write your code here
}
x"hackerranks"
y"hackers"
expected7
sign in to submit