brutal force + optimization, easy understanding c++
brutal force is simple. What we need to do is to find the repeating cycle and move the pointers forward. When the s2 ends and the s1 pointer is on the previous 
brutal force is simple. What we need to do is to find the repeating cycle and move the pointers forward. When the s2 ends and the s1 pointer is on the previous positions, then you get the repeating things.\n\nLet\'s say s1 = "abab", s2= "aabb".\n\n```\nabab abab abab abab abab\na ab  ba  ab b a ab  b\n      |      |       |\np1:   1      3       1\n```\nIn the above chart, when string 2 ends, p1 positions are 1, 3, 1. Here we can find the repeating cycle, which consists of 3 s1 and 2 s2. Then we can calculate how many round are there to go and then easily move the points to the very end part.\n```\n    int getMaxRepetitions(string s1, int n1, string s2, int n2) {\n        for(auto c : s2) {\n            // preventive checkings, it could be O(n), but who cares.\n            if (s1.find(c) == string::npos) return 0;\n        }\n        int p1 = 0, p2 = 0, mark = 0;\n        while(p1 < s1.length() * n1) {\n            char c = s2[p2 % s2.length()];\n            while(s1[p1 % s1.length()] != c && p1 < s1.length() * n1) p1 ++;\n            p2++;\n            p1++;\n            // optimization part below\n            if (p2 % s2.length() == 0) {\n                if (p2 == s2.length()) {\n                    mark = p1; // mark the position in s1, when the first s2 ends\n                } else if (p1 % s1.length() == mark % s1.length()) {\n                    // s1 reaches the same position, which means the repeating cycle found. \n                    //Then we can leap forward.\n                    int round = (s1.length() * n1 - p1) / (p1 - mark);\n                    p1 += round * (p1 - mark);\n                    p2 += round * (p2 - s2.length());\n                }\n            }\n        }\n        return p2 / s2.length() / n2;\n    }\n\t\t```
[]