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

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

Salesforce logoSalesforce● HardNEW GRADOA

Updated Sep 2026

QuestionFunctionExamples

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 interview questions

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026
  • Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • Minimum Merge ConflictsAmazon · OA
  • String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions
  • Distinct MovesMeesho · OA
  • Compressed Representation SizeMicrosoft · OAMicrosoft interview questions
  • Find Minimum OperationsIBM · OAIBM interview questions
  • String Challenge (Generic)TikTok · OATikTok interview questions
  • Maximize the Lottery IDCitadel · OACitadel interview questions
  • Sum of All ValuesFlexport · OAFlexport interview questions
  • Maximum Crayon Removal ScoreWells Fargo · OAWells Fargo interview questions

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int findLongestSubsequenceCommonToXAsSubstringInY(String x, String y) {
      // write your code here
    }

}
Checking account…