Solution Explanation in link below
https://open.substack.com/pub/hustlercoder/p/mastering-string-repetition?r=1f5fq7&utm_campaign=post&utm_medium=web&showWelcomeOnShare=falseCode
https://open.substack.com/pub/hustlercoder/p/mastering-string-repetition?r=1f5fq7&utm_campaign=post&utm_medium=web&showWelcomeOnShare=false

# Code
```python3 []
class Solution:
    def getMaxRepetitions(self, s1: str, n1: int, s2: str, n2: int) -> int:
        if n1 == 0:
            return 0

        # Counters for the number of s2 repetitions and the current index in s2
        s2_count = 0
        index_s2 = 0

        # Dictionary to store the state (index in s2) at a given count of s1 iterations
        recall = {}

        # Iterate over each repetition of s1
        for k in range(1, n1 + 1):
            # Traverse the current s1
            for char in s1:
                if char == s2[index_s2]:
                    index_s2 += 1
                    if index_s2 == len(s2):
                        s2_count += 1
                        index_s2 = 0

            # If we have seen this state before, a cycle is detected
            if index_s2 in recall:
                # Previous state details: (previous iteration count, s2_count at that moment)
                previous_k, previous_s2_count = recall[index_s2]
                cycle_length = k - previous_k
                cycle_s2_count = s2_count - previous_s2_count

                # Calculate how many full cycles can fit into the remaining iterations
                remaining = n1 - k
                cycles = remaining // cycle_length
                s2_count += cycles * cycle_s2_count

                # Process the leftover repetitions after accounting for full cycles
                remainder = remaining % cycle_length
                for _ in range(remainder):
                    for char in s1:
                        if char == s2[index_s2]:
                            index_s2 += 1
                            if index_s2 == len(s2):
                                s2_count += 1
                                index_s2 = 0
                return s2_count // n2
            else:
                # Record the current state with its corresponding iteration count and s2_count
                recall[index_s2] = (k, s2_count)

        return s2_count // n2

# Example usage:
# sol = Solution()
# print(sol.getMaxRepetitions("acb", 4, "ab", 2))  # Expected output: 2

```
['Python3']