Java 5 ms solution, similar idea from #418 Sentence Screen Fitting
The idea is similar with #418 sentence screen fitting, e.g. store the next index \n1. At Prepare funciton, calculate for each idx in s1, the next idx for fittin
The idea is similar with #418 sentence screen fitting, e.g. store the next index \n1. At Prepare funciton, calculate for each idx in s1, the next idx for fitting exactly one s2, and how many s1 is needed\n2. Find the Looping starting index of s1, which means:\n         m s1 can fit n s2, always from idx to idx at s1, \n         also need to know how many times we used s1 before reaching loop index,\n         and how many times we get s2 before reaching loop index\n3. Using those parameters we can calculate overall how many times we can get s2 from n1 s1\n```\n    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n\tif (s1.length()*n1 < s2.length()*n2) return 0;\n        char[] ss1 = s1.toCharArray();\n        char[] ss2 = s2.toCharArray();\n        for (char c: ss2) {\n        \tif (!s1.contains(c+"")) return 0;\n        }\n        int[] s1NextIdx = new int[ss1.length];\n        int[] s1Costs = new int[ss1.length];\n        prepare(ss1, ss2, s1NextIdx, s1Costs);\n        int s1used = 0;\n        int s1Idx = 0;\n        int s2Count = 0;\n        boolean[] used = new boolean[ss1.length];\n        while (!used[s1Idx] && (s1used+s1Costs[s1Idx] <= n1)) {\n            used[s1Idx] = true;\n            s1used += s1Costs[s1Idx];\n            s1Idx = s1NextIdx[s1Idx];\n            s2Count++;\n        }\n        if (s1used+s1Costs[s1Idx] > n1) return s2Count/n2;\n        if (s1Idx == 0 && n1%s1used == 0) {\n        \treturn s2Count*n1/s1used/n2;\n        }\n        int startIdx = 0;\n        int preS2Count = 0;\n        int preS1Used = 0;\n        \n        while (startIdx != s1Idx) {\n            s1used -= s1Costs[startIdx];\n            preS1Used += s1Costs[startIdx];\n            startIdx = s1NextIdx[startIdx];\n            s2Count--;\n            preS2Count++;\n        }\n        if (preS2Count > 0) preS1Used++;\n        int times = (n1-preS1Used)/s1used;\n        s2Count = s2Count*times + preS2Count;\n        s1used = preS1Used + times*s1used;\n        //calcualting the tail part\n        while (s1used+s1Costs[s1Idx] <= n1) {\n            s1used += s1Costs[s1Idx];\n            s1Idx = s1NextIdx[s1Idx];\n            s2Count++;\n        }\n        return s2Count/n2;\n    }\n    private void prepare(char[] s1, char[] s2, int[] s1NextIdx, int[] s1Cost) {\n        boolean[] used = new boolean[s1.length];\n        int idx = 0;\n        while (!used[idx]) {\n            used[idx] = true;\n            int curr = idx;\n            int count = 0;\n            int s2idx = 0;\n            while (s2idx < s2.length) {\n                if (s1[curr++] == s2[s2idx]) {\n                    s2idx++;\n                }\n                if (curr >= s1.length) {\n                    curr = 0;\n                    count++;\n                }\n            }\n            s1Cost[idx] = count;\n            s1NextIdx[idx] = curr;\n            idx = curr;\n        }\n    }\n```
[]