[Java] DP like Solution
iterate through S1 again and again, track the pointer position of S2 at the end of each S1 iteration\n continue until the S2 pointer comes back to previous posi
* iterate through S1 again and again, track the pointer position of S2 at the end of each S1 iteration\n* continue until the S2 pointer comes back to previous position, which means we\'ve found a cycle\n\t* break up into 3 parts: pre-cycle, in-cycle, post-cycle\n\t\t* calculate loop count for the in-cycle part\n\t\t* snitch pre-cycle and post-cycle together, and calculate the loop count for this combined parts\n```\nclass Solution {\n    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n        int nn1 = s1.length();\n        int nn2 = s2.length();\n        \n        int[][] records = new int[2][n1+1];\n        Arrays.fill(records[0], -1);\n        int index2 = 0, count = 0;\n        int cycleStart = -1, cycleEnd = -1, cycleCount = -1;\n        for (int i = 1; i <= n1; i++) {\n            for (int j = 0; j < nn1; j++) {\n                if (s1.charAt(j) == s2.charAt(index2)) {\n                    index2++;\n                }\n                if (index2 == nn2) {\n                    index2 = 0;\n                    count++;\n                }\n            }\n            for (int k = 1; k < i; k++) {\n                if (records[0][k] == index2) { \n                    // we find the cycle, record start/end/count and then quit the loop\n                    cycleStart = k;\n                    cycleEnd = i;\n                    cycleCount = count - records[1][k];\n                }\n            }\n            if (cycleStart != -1) {\n                break;\n            }\n            records[0][i] = index2;\n            records[1][i] = count;\n        }\n        \n        if (cycleStart == -1) {\n            return count / n2;\n        }\n        \n        int res = 0;\n        // calculate cycle\n        int cycleN = (n1 - cycleStart) / (cycleEnd - cycleStart);\n        res = cycleN * cycleCount;\n        // snitich pre-cycle and post-cycle parts\n        res += records[1][n1 - cycleN * (cycleEnd - cycleStart)];\n        \n        return res / n2;\n    }\n}\n```
[]