FastPrepString Subsequences 🐳
Problems/String Subsequences 🐳

String Subsequences 🐳

Morgan Stanley logoMorgan Stanley● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Given two strings, determine the number of times the first one appears as a subsequence in the second one. A subsequence is created by eliminating any number of characters from a string (possibly 0) without changing the order of the characters retained.

Function

getSubsequenceCount(s1: String, s2: String) → long

Complete the function getSubsequenceCount in the editor below.

getSubsequenceCount has the following parameters:

  • string s1: the first string, which always has a length of 3
  • string s2: the second string

Returns int: the number of times s1 appears as a subsequence in s2

Examples

Example 1

s1 = "HRW"s2 = "HERHRWS"return = 3

HRW appears at 1-based positions (1, 3, 6), (1, 5, 6), and (4, 5, 6), so the count is 3.

Example 2

s1 = "ELO"s2 = "HELLOWORLD"return = 4

ELO appears at 1-based positions (2, 3, 5), (2, 3, 7), (2, 4, 5), and (2, 4, 7), so the count is 4.

Example 3

s1 = "ABC"s2 = "ABCBABC"return = 5

ABC appears at 1-based positions (1, 2, 3), (1, 2, 7), (1, 4, 7), (1, 6, 7), and (5, 6, 7), so the count is 5.

Constraints

  • length of s1 = 3
  • 1 ≤ length of s2 ≤ 5*105
  • s1 and s2 consist of uppercase English letters, A-Z.

More Morgan Stanley interview questions

  • Unique Grid PathsPHONE SCREEN · Seen Oct 2026
  • Generate Strings of Length at Least ThreeONSITE INTERVIEW · Seen Sep 2026
  • Three-Resource 0/1 KnapsackOA · Seen Sep 2026
  • Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
  • Kth Largest Array ElementONSITE INTERVIEW · Seen Jul 2026
  • Maximum Total of Nonadjacent RatingsOA · Seen Jul 2026
  • Run-Length Encode Consecutive Letter RunsONSITE INTERVIEW · Seen Jul 2026
  • Count Shipment SchedulesOA · Seen Apr 2026
  • Delete and EarnOA · Seen Apr 2026
  • Interleave Array HalvesOA · Seen Apr 2026

Similar questions at other companies

  • Palindromic Substrings (LC 647 :)Citadel · OACitadel interview questions
  • Palindromic SubstringsAmazon · OA
  • Longest Palindromic SubsequenceAXQ Capital · OA
  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • Longest Subsequence That Is a SubstringBooking.com · OA
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
  • Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
  • Longest String ChainVisa · OAVisa interview questions
  • Minimum-Cost Digit String DecodingSquadStack.ai · OA
  • Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions

Morgan Stanley interview experiences

  • Morgan Stanley Apprenticeship and Tech Interviews: 6 Experiences
  • Morgan Stanley New Grad Technology Analyst: 2 Experiences
  • Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)
  • Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
  • Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
  • Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)
All Morgan Stanley interview questionsSee Morgan Stanley hiring insights
Saved
class Solution {
    public long getSubsequenceCount(String s1, String s2) {
      // write your code here
    }

}
Checking account…