Nice fast(ish) 115ms simple bruteforce Java complete with unit test (that's right)
Code should be self-explanatory\n\n\nimport org.junit.jupiter.api.Test;\n\nimport java.util.HashSet;\nimport java.util.Set;\n\nimport static org.junit.jupiter.a
Code should be self-explanatory\n\n```\nimport org.junit.jupiter.api.Test;\n\nimport java.util.HashSet;\nimport java.util.Set;\n\nimport static org.junit.jupiter.api.Assertions.assertEquals;\n\npublic class Solution {\n\n    private int countS2inS1(final char[] s1, final char[] s2) {\n        int count = 0;\n        int s2Pointer = 0;\n\n        for (final char c1 : s1) {\n            if (c1 == s2[s2Pointer]) {\n                s2Pointer++;\n\n                if (s2Pointer == s2.length) {\n                    s2Pointer = 0;\n                    count++;\n                }\n            }\n        }\n\n        return count;\n    }\n\n    public int getMaxRepetitions(final String s1, final int n1, final String s2, final int n2) {\n        final Set<Character> s1Chars = new HashSet<>();\n\n        for (final char c1 : s1.toCharArray()) {\n            s1Chars.add(c1);\n        }\n\n        final Set<Character> s2Chars = new HashSet<>();\n\n        for (final char c2 : s2.toCharArray()) {\n            s2Chars.add(c2);\n        }\n\n        if (s1Chars.size() == 1 && s2Chars.size() == 1 && s1Chars.iterator().next() == s2Chars.iterator().next()) {\n            return (s1.length() * n1) / (s2.length() * n2);\n        }\n\n        final StringBuilder sb1 = new StringBuilder();\n\n        for (int i = 0; i < (n1 / n2); i++) {\n            sb1.append(s1);\n        }\n\n        if (sb1.length() == 0) {\n            sb1.append(s1);\n            return Math.max(0, countS2inS1(sb1.toString().toCharArray(), s2.toCharArray()) - 1);\n        }\n\n        return countS2inS1(sb1.toString().toCharArray(), s2.toCharArray());\n    }\n\n    @Test\n    public void test() {\n        assertEquals(2, new Solution().getMaxRepetitions("acb", 4, "ab", 2));\n        assertEquals(4, new Solution().getMaxRepetitions("aaa", 3, "aa", 1));\n        assertEquals(7, new Solution().getMaxRepetitions("baba", 11, "baab", 1));\n        assertEquals(1, new Solution().getMaxRepetitions("adasfdgdftadwfwfereredsfssas", 500, "fw", 555));\n        assertEquals(100000000, new Solution().getMaxRepetitions("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1000000, "a", 1));\n        assertEquals(200000, new Solution().getMaxRepetitions("aahumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenazkycxf", 1000000, "aac", 10));\n        assertEquals(0, new Solution().getMaxRepetitions("musicforever", 10, "lovelive", 100000));\n    }\n\n}\n```
[]