


S1[“abc” 4] , S2 = [“ab” 2]
Here, 'S1' = ”abcabcabcabc” and 'S2' = ”abab”,
After deleting all ‘c’ from 'S1' becomes S'1 = “abababab”, which can also be written as
S'1 =[“abab" 2] = [S2 2].
Hence the 'M' = 2.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows
The first line of each test case contains a string 's1' and an integer 'N1', where 'S1' = [s1, n1].
Second line of each test case contains a string 's2' and an integer 'N2', where 'S2' = [s2, n2].
For each test case, you have to return an integer M such that [S2,M] can be obtained from S1.
You do not need to print anything or take input. This already has been taken care of. Just implement the function.
1 <= T <= 5
1 <= length of s1, length of s2 <= 100
1 <= n1, n2 <= 10^3
Time Limit: 1 sec
We have to find ‘M’ such that [S2,M] is the largest subsequence. As we know ‘S2’ = [s2, N2] so we can find the number of times ‘s2’, can be obtained from ‘S1’ and then we can divide it by ‘N2’ to find the ‘M’. (number of repetitions of ‘S2’ in ‘S1’).
Algorithm:-
According to the Pigeonhole principle if we have to put ‘N’ things in 'M' boxes where ‘N’ > ‘M’ then there must be more than one item in at least one box. So if N1 > N2 then there must be a repeating pattern. In this approach, we are finding the pattern then after finding the pattern we can find the occurrence for the whole string.
Algorithm:-