java solution | 4ms runtime | with brief explanation
Code \u2615\uFE0F\n\n\n// Count the repetitions\n// LeetCode: https://leetcode.com/problems/count-the-repetitions/\n\nclass Solution {\n    public int getMaxRep
## Code \u2615\uFE0F\n\n```\n// Count the repetitions\n// LeetCode: https://leetcode.com/problems/count-the-repetitions/\n\nclass Solution {\n    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n        int[] next = new int[s2.length() + 1];\n        int[] count = new int[s2.length() + 1];\n        int j = 0, cnt = 0;\n        for (int k = 1; k <= n1; k++) {\n            for (int i = 0; i < s1.length(); i++) {\n                if (s1.charAt(i) == s2.charAt(j)) {\n                    j++;\n                    if (j == s2.length()) {\n                        j = 0;\n                        cnt++;\n                    }\n                }\n            }\n            count[k] = cnt;\n            next[k] = j;\n            for (int start = 0; start < k; start++) {\n                if (next[start] == j) {\n                    int prefixCount = count[start];\n                    int patternCount = (count[k] - count[start]) * ((n1 - start) / (k - start));\n                    int suffixCount = count[start + (n1 - start) % (k - start)] - count[start];\n                    return (prefixCount + patternCount + suffixCount) / n2;\n                }\n            }\n        }\n        return count[n1] / n2;\n    }\n}\n```\n\n## Explanation ..\n\n. For each repetition of s1, count the number of times we see s2\n. Store the seen count for each repetition of s1\n. Store the index of s2 where we stopped after each repetition of s1\n. For each repetition of s1, check if we\'ve seen this index of s2 before\n. If we have, then we\'ve found a repeating pattern\n. The number of times we see s2 in the pattern is (count[k] - count[start])\n. The number of times we see s2 outside the pattern is (count[start + (n1 - start) % (k - start)] - count[start])\n. The number of times we see s2 in total is (prefixCount + patternCount + suffixCount)\n. The number of times we see s2 in total divided by n2 is the answer\n
['Java']