Get Patch Sequence
Updated
Problem statement
A clothing company uses a reusable string patch to create designerWords. Begin with designerWords.length blank positions. Applying the patch at zero-based index i writes every character of patch into positions i through i + patch.length - 1. Written characters overwrite anything already present at those positions.
A sequence is valid when all positions spell designerWords after the final application. Each starting index may appear at most once.
Return a valid sequence using the fewest patch applications. If several minimum-length sequences exist, return the lexicographically smallest one: compare the first differing index, and if one sequence is a prefix of another, the shorter sequence is smaller. Return [-1] when no valid sequence exists.
Function
getPatchSequence(patch: String, designerWords: String) → int[]Examples
Example 1
patch = "ab"designerWords = "aab"return = [0, 1]The patch needs to be used in the following way to create the desired word: Place the first patch at index 0 to get "ab". Place the second patch at index 1 to form "aab". The requirement states that the second patch 'b' of the first patch overlaps with 'a' of the second patch.
Example 2
patch = "yz"designerWords = "yzzz"return = [2, 1, 0]:)
Constraints
1 ≤ patch.length ≤ designerWords.length ≤ 20patchanddesignerWordscontain only lowercase English letters.- Each valid starting index is in the inclusive range
0throughdesignerWords.length - patch.length. - Each starting index may appear at most once.
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
- Lexicographically Largest IdentifierAmazon · OA
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
- Binary CircuitAkuna Capital · OAAkuna Capital interview questions
- Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
- Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
- Palindromic StringsNVIDIA · OANVIDIA interview questions
- Max Number of OperationsSalesforce · OASalesforce interview questions
- Viral Content BalancerTikTok · OATikTok interview questions
- Good Binary StringsBNP Paribas · OA
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)