Python solution with finding a cycle
The idea is to find the number of occurences of s2 in S1 and to find a cycle in s1.\nHere is the code:\n\ndef solve(s1, n1, s2, n2):\n    s1l, s2l, S1L = len(s1
The idea is to find the number of occurences of s2 in S1 and to find a cycle in s1.\nHere is the code:\n```\ndef solve(s1, n1, s2, n2):\n    s1l, s2l, S1L = len(s1), len(s2), len(s1) * n1\n    # Maps from idx in s1 to \n    #   (num characters from begin, num occurences of s2)\n    numChars = { 0: (0, 0) } \n    i, j = 0, 0\n    s2Cnt = 0\n    cntr = 10002\n    while cntr and i < S1L:\n        cntr -= 1\n        idxi, idxj = i % s1l, j % s2l\n        if s2[idxj] == s1[idxi]:\n            j += 1\n            if j % s2l == 0: s2Cnt += 1\n        i += 1\n        idxi, idxj = i % s1l, j % s2l\n        if j and idxj == 0:\n            if idxi not in numChars:\n                # save the current idx of occurence of s2\n                numChars[idxi] = (i, s2Cnt)\n            else:\n                # found a cycle\n                charsInCycle, occurencesBefore = i - numChars[idxi][0], numChars[idxi][1]\n                numberOfCycles = (S1L - i) // charsInCycle\n                s2Cnt += (s2Cnt - occurencesBefore) * numberOfCycles\n                i += numberOfCycles * charsInCycle\n                # go till end normally\n                while i < S1L:\n                    if s1[i % s1l]==s2[j % s2l]:\n                        j += 1\n                        if j % s2l == 0:\n                            s2Cnt += 1\n                    i += 1\n                return s2Cnt // n2\n    return s2Cnt // n2\n\nclass Solution:\n    def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int:\n        return solve(s1,n1,s2,n2)\n```
[]