Problem · Dynamic Programming
Find Longest Subsequence Common to X as Substring in Y (MLE :)
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
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
- Strings With No k Consecutive Identical CharactersOA · Seen Feb 2026
- Spam ClassificationSeen Jun 2025
public int findLongestSubsequenceCommonToXAsSubstringInY(String x, String y) {
// write your code here
}
x"hackerranks"
y"hackers"
expected7
sign in to submit