FastPrepFastPrep
Problem Brief

Get Patch Sequence

OA

A clothing company wants to start a new line of clothing made from recycled clothes. The company wants this line to consist only of words formed from letters 'a' to 'z'. The creative team is facing challenges as they need to use a similar patch multiple times to achieve the desired design. To address this, the product team needs to find the sequence in which they should use the patch to get the desired words on the clothing.

Input:

The first line consists of a string patch, representing the patch.

The second line consists of a string designerWords, representing the words to be printed on the clothing.

Output: Print N space-separated integers indicating the sequence in which the patch should be used to obtain the desired words. If there is no possible way, then print -1.

Note: If multiple possible sequences exist, print the smallest permutation.

Function Description

Complete the function getPatchSequence in the editor.

getPatchSequence has the following parameters:

  1. 1. String patch: a string representing the patch
  2. 2. String designerWords: a string representing the words to be printed

Returns

int[]: an array of integers indicating the sequence in which the patch should be used, or an array with a single element -1 if it's not possible

1Example 1

Input
patch = "ab", designerWords = "aab"
Output
[0, 1]
Explanation
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.

2Example 2

Input
patch = "yz", designerWords = "yzzz"
Output
[2, 1, 0]
Explanation
:)
public int[] getPatchSequence(String patch, String designerWords) {
  // write your code here
}
Input

patch

"ab"

designerWords

"aab"

Output

[0, 1]

Sign in to submit your solution.