63ms easy sol beats 83% users
\nI tried :|\n# Code\n\nvar getMaxRepetitions = function(s1, n1, s2, n2) {\n    let index = 0; // Pointer for s2\n    let count1 = 0; // Counter for s1 repetiti
![image.png](https://assets.leetcode.com/users/images/03c97a22-5ffd-4e00-94a4-b975bba8388c_1715326417.908811.png)\nI tried :|\n# Code\n```\nvar getMaxRepetitions = function(s1, n1, s2, n2) {\n    let index = 0; // Pointer for s2\n    let count1 = 0; // Counter for s1 repetitions\n    let count2 = 0; // Counter for s2 repetitions\n    let seen = {}; // Store the count of s2 appearances at each index of s1\n\n    while (count1 < n1) {\n        for (let char of s1) {\n            if (char === s2[index]) {\n                index++;\n                if (index === s2.length) {\n                    index = 0;\n                    count2++;\n                }\n            }\n        }\n\n        count1++;\n\n        // If we\'ve seen the current index and count of s2 before, we can calculate the loop size\n        if (index in seen) {\n            // Calculate the loop size\n            let loopSize = count1 - seen[index][0];\n            // Calculate the number of s1 repetitions until we repeat the loop\n            let remainingRepetitions = n1 - count1;\n            // Calculate the number of s2 repetitions within the loop\n            let loopS2Count = count2 - seen[index][1];\n            // Calculate the number of s2 repetitions in the remaining s1 repetitions\n            let remainingS2Count = loopS2Count * Math.floor(remainingRepetitions / loopSize);\n            // Update the count1 to the end of the loop\n            count1 += Math.floor(remainingRepetitions / loopSize) * loopSize;\n            count2 += remainingS2Count;\n        } else {\n            seen[index] = [count1, count2];\n        }\n    }\n\n    // Calculate the maximum number of times s2 can be obtained from s1\n    return Math.floor(count2 / n2);\n};\n\n```
['JavaScript']