Use next array, java solution
\nclass Solution{\n    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n        int len1 = s1.length();\n        int len2 = s2.length();\n 
```\nclass Solution{\n    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {\n        int len1 = s1.length();\n        int len2 = s2.length();\n        boolean c[] = new boolean[26];\n        for (int k = 0; k < len1; k++) {\n            c[s1.charAt(k) - \'a\'] = true;\n        }\n\n        for (int k = 0; k < len2; k++) {\n            if (!c[s2.charAt(k) - \'a\']) {\n                return 0;\n            }\n        }\n\n\n        int[] dp = new int[len1];\n        for (int i = 0; i < len1; i++) {\n            dp[i] = findNextIndex(s1, s2, i);\n        }\n\n        int []fast = new int[len1];\n        for (int i = 0; i < len1; i++) {\n            int t = i;\n            int step = 0;\n            for (int j = 0; j < 1000; j++) {\n                step += dp[t];\n                t = t + dp[t];\n                t %= len1;\n            }\n    \n            fast[i] = step;\n        }\n\n        int i = 0;\n        int limit = len1 * n1;\n        int sum = 0;\n        while(i < limit) {\n            if (dp[i%len1] < 0) break;\n            int fastNext = i + fast[i%len1];\n            if (fastNext <= limit) {\n                i = fastNext;\n                sum+=1000;\n                continue;\n            }\n\n            i = i + dp[i%len1];\n            if (i <= limit)\n            sum++;\n           \n        }\n\n        return sum/n2;\n    }\n\n    private int findNextIndex(String s1, String s2, int i) {\n        int j = 0;\n        int step = 0;\n        while(j < s2.length()) {\n            if (s1.charAt(i) == s2.charAt(j)) {\n                j++;\n            }\n\n            i++;\n            step++;\n            i %= s1.length();\n        }\n        return step;\n    }\n}\n```
[]