Simple simulation with some trick
Intuition\nUse the first string to match the pattern(second string) as many as possible.\n\n# Approach\n Describe your approach to solving the problem. \nThe tr
# Intuition\nUse the first string to match the pattern(second string) as many as possible.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe trick is trying to find the "loop" to accelerate the matching process.\nRecord the state of the pointer to the first string.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def getMaxRepetitions(self, a: str, n1: int, b: str, n2: int) -> int:\n        cnt_a = 0\n        cnt_b = 0\n        m, n = len(a), len(b)\n        f = {}\n        i = 0\n        while cnt_a < n1:\n            j = 0\n            while j < n:\n                while i < m and a[i] != b[j]:\n                    i = i + 1\n                if i == m:\n                    i = 0\n                    cnt_a += 1\n                    if cnt_a >= n1:\n                        return cnt_b // n2\n                    continue\n                i, j = i + 1, j + 1\n            cnt_b += 1\n            if i in f:\n                db = cnt_b - f[i][0]\n                da = cnt_a - f[i][1]\n                while cnt_a + da < n1:\n                    cnt_a += da\n                    cnt_b += db\n                f = {}\n                continue\n            f[i] = [cnt_b, cnt_a]\n        return cnt_b // n2\n```
['Python3']