Problem · Dynamic Programming

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

Learn this problem
HardSalesforceNEW GRADOA
See Salesforce hiring insights

Problem statement

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.

Function

findLongestSubsequenceCommonToXAsSubstringInY(x: String, y: String) → int

Examples

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
checking account