


'S'= “#####” 'TARGET' = “ababbb” 'STAMP' = “ab”
Stamping substring starting at 4 , 'S' = “####ab”
Stamping substring starting at 3 , 'S' = “###abb”
Stamping substring starting at 2 , 'S' = “##abbb”
Stamping substring starting at 0 , 'S' = “ababbb”
Answer = [4, 3, 2, 0]
The first line of input contains an integer T’ denoting the number of test cases to run.
The first line of each test case contains two space-separated integers ‘N’ and ‘M’ denoting the length of 'TARGET' and 'STAMP' respectively.
The second line of each test case contains the string 'TARGET'.
The third line of each test case contains the string 'STAMP'.
For each test case, return the moves of size not greater than 5 * 'N', to convert 'S' into 'TARGET'.
Output for each test case is printed in a separate line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N, M <= 1000
M <= N
TARGET and stamp have only lower case English characters.
Time Limit: 1 sec
We will do the process in reverse. We will iterate over the substrings of ‘TARGET’ and try to convert them into ‘#’. Two characters of ‘TARGET’ and ‘STAMP’ matches if they are equal or the character in ‘TARGET’ is already replaced with a ‘#’.
We will maintain an array of indexes for each substring starting at ‘i’ which are not matching with character in ‘STAMP’. If some substring matches with ‘STAMP’ we will insert all its indexes in ‘STACK’.
We will pop an index from the ‘STACK’ and remove it from all the UNMATCHED array that contains it. If any of the UNMATCHED arrays becomes empty we will push it to the STACK and repeat the process.
The steps are as follows: