Ridiculous
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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```\nimport java.util.*;\n\npublic class Solution {\n\n    // aaa  x2     a   === 6 times\n    // aaa  x2     aa  === 3 times\n    // aaba x2     aa  === 3 times\n\n    //         v              v\n    // nlhqgllunmelaylnlhqgllunmelaylnlhqgllunmelaylnlhqgllunmelaylnlhqgllunmelaylnlhqgllunmelayl\n\n    // 012345678       012345678\n    // nlhqgllunmelayl nlhqgllunmelayl\n    //  0      1  2  0 12   0  1  2\n\n    // lnl\n\n    // aaa  x3     aa  === 4 times\n    // AaA aAa (Aaa) EXAMPLE-1; leftover S1 with 1 more match!!!!\n    //          ^\n\n    // aaa  x2     a   === 6 times\n    // aaa  x2     aa  === 3 times\n    // aaba x2     aa  === 3 times\n\n    // AabA aAba Aaba\n    //           ^\n    // again match s1[0] == s2[0]\n    // so for every 2 s1 we find 3 s2\n\n    // Instead of looping blindly N1 times over S1, we want to find patterns (substring that repeats)\n    // Then next time we find the PATTERN, we skip over it and cnt += numS2InPattern\n\n    // To find pattern, record the mapping s1[x] == x2[y] the SECOND TIME the same match happens, the PATTERN ENDS!\n    // it started at the FIRST MATCH!\n    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n        int i = 0, j = 0;\n        int s1N = s1.length();\n        int s2N = s2.length();\n        int cnt = 0;\n        int[][] s2ToS1ToLastPatternEnd = new int[s2N][s1N];\n        int[][] s2ToS1ToLastPatternCnt = new int[s2N][s1N];\n        for (int k = 0; k < s2N; k++) Arrays.fill(s2ToS1ToLastPatternEnd[k], -1);\n        int maxChars = n1 * s1N;\n        for (; i < maxChars; i++) {\n            int x = i % s1N;\n            int y = j % s2N;\n            char c1 = s1.charAt(x);\n            char c2 = s2.charAt(y);\n\n            // acb acb acb acb        ab\n            if (c1 == c2) {\n                if (y == s2N - 1) cnt++;\n                int pLen = i - s2ToS1ToLastPatternEnd[y][x];\n\n                if (s2ToS1ToLastPatternEnd[y][x] != - 1 && i + pLen < maxChars) { // pattern found again! enough chars to match all of it\n                    cnt += cnt - s2ToS1ToLastPatternCnt[y][x];\n                    i += pLen;\n                }\n                s2ToS1ToLastPatternEnd[y][x] = i; // pattern end\n                s2ToS1ToLastPatternCnt[y][x] = cnt; // cnt at pattern end\n                j++;\n            }\n        }\n\n        return cnt / n2;\n    }\n\n\n\n}\n\n```
['Java']