PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Salesforce

Find longest subsequence of x that is a substring of y

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string-algorithm skills and conceptual understanding of subsequences versus substrings, along with attention to algorithmic efficiency when relating non-contiguous selections to contiguous patterns.

  • medium
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Find longest subsequence of x that is a substring of y

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: HR Screen

Given two strings `x` and `y`, compute the **maximum length** of a string `s` such that: - `s` is a **subsequence** of `x` (can delete zero or more characters from `x` without reordering the remaining characters), and - `s` is a **substring** of `y` (must appear as a contiguous block in `y`). Return the maximum possible length. ### Example - `x = "abcd"`, `y = "abdc"` - One optimal choice is `"abd"` (subsequence of `x`, substring of `y`), so the answer is `3`. ### Sample - `x = "hackerranks"`, `y = "hackers"` - Output: `7` (because `"hackers"` is a subsequence of `x` and also a substring of `y`).

Quick Answer: This question evaluates string-algorithm skills and conceptual understanding of subsequences versus substrings, along with attention to algorithmic efficiency when relating non-contiguous selections to contiguous patterns.

Related Interview Questions

  • Solve Two OA Coding Problems - Salesforce (medium)
  • Maximize events attended given date ranges - Salesforce (medium)
  • Implement common data-structure and JS tasks - Salesforce (medium)
  • Minimize operations to reduce integer to zero - Salesforce (medium)
  • Implement an LFU cache with O(1) operations - Salesforce (medium)
Salesforce logo
Salesforce
Nov 13, 2025, 12:00 AM
Software Engineer
HR Screen
Coding & Algorithms
19
0

Given two strings x and y, compute the maximum length of a string s such that:

  • s is a subsequence of x (can delete zero or more characters from x without reordering the remaining characters), and
  • s is a substring of y (must appear as a contiguous block in y ).

Return the maximum possible length.

Example

  • x = "abcd" , y = "abdc"
    • One optimal choice is "abd" (subsequence of x , substring of y ), so the answer is 3 .

Sample

  • x = "hackerranks" , y = "hackers"
    • Output: 7 (because "hackers" is a subsequence of x and also a substring of y ).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Salesforce•More Software Engineer•Salesforce Software Engineer•Salesforce Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.