Class Solution
- java.lang.Object
-
- g0901_1000.s0936_stamping_the_sequence.Solution
-
public class Solution extends Object
936 - Stamping The Sequence.Hard
You are given two strings
stampandtarget. Initially, there is a stringsof lengthtarget.lengthwith alls[i] == '?'.In one turn, you can place
stampoversand replace every letter in theswith the corresponding letter fromstamp.-
For example, if
stamp = "abc"andtarget = "abcba", thensis"?????"initially. In one turn you can:- place
stampat index0ofsto obtain"abc??", - place
stampat index1ofsto obtain"?abc?", or - place
stampat index2ofsto obtain"??abc".
Note that
stampmust be fully contained in the boundaries ofsin order to stamp (i.e., you cannot placestampat index3ofs). - place
We want to convert
stotargetusing at most10 * target.lengthturns.Return an array of the index of the left-most letter being stamped at each turn. If we cannot obtain
targetfromswithin10 * target.lengthturns, return an empty array.Example 1:
Input: stamp = “abc”, target = “ababc”
Output: [0,2]
Explanation: Initially s = “?????”.
- Place stamp at index 0 to get “abc??”.
- Place stamp at index 2 to get “ababc”.
[1,0,2] would also be accepted as an answer, as well as some other answers.
Example 2:
Input: stamp = “abca”, target = “aabcaca”
Output: [3,0,1]
Explanation: Initially s = “???????”.
- Place stamp at index 3 to get “???abca”.
- Place stamp at index 0 to get “abcabca”.
- Place stamp at index 1 to get “aabcaca”.
Constraints:
1 <= stamp.length <= target.length <= 1000stampandtargetconsist of lowercase English letters.
-
-
-
Constructor Summary
Constructors Constructor Description Solution()
-