Calculate early if cycling is detected
Intuition\n Describe your first thoughts on how to solve this problem. \nDetect looping alignment of substring finding and use that to calculate what the total 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDetect looping alignment of substring finding and use that to calculate what the total would be without having to count it out completely.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLoop through s1 finding in-order occurrances of the characters from s2, counting cycles of s1 and s2 until the first cahracter of s2 is found again in the same position of s1 as it was the first time. also record s1 count at each s2 loop for later.\n\nIf n1 cycles of s1 have been reached before s2 alignment cycles, do simple calculation ([s2 cycles] / n2).\n\nIf s2 alignment is reached, total number of s2 cycles is ((n1 * [s2 cycles done]) / [s1 cycles done]) - ([s1 cycle s2 last completed on] == [final s1 cycle]). To get max cycles of n2 cycles of s2, integer divide by n2.\n\nIt might be needed to also detect s2 alignment looping that hapens on the 2nd or 3rd alignment position but never returns to the first, since 600ms seems a bit long for 50 testcases. Could be implemented as an array of max string length, each time s2 first char is found check for an entry at current s1 read point, and if there isn\'t one enter [s2 cycle number] on that array point. found entry = break, subtract entry from s2 cycle number, calculate cycles, then add back on before divide by n2.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n\xB7s)$$ - depends on length of the strings and how they loop. Worst case they never loop and the entire n1*s1 sequence has to be searched.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ \n\n# Code\n```\nint getMaxRepetitions(char * s1, int n1, char * s2, int n2){\n    int a = 0, b = 0, c = 0, d = 0, e = -1, f = 0;\n    char s1r, s2r = s2[b];\n    while(c < n1)\n    {   if(!(s1r = s1[a++])) { c++; a = 0; continue; } // loop reading of s1\n        if(s2r == s1r) \n        {   if(e == -1) e = a; else if((e == a) && (b == 0)) goto earlycalc; \n            s2r = s2[++b];\n        }\n        if(!s2r) { s2r = s2[(b = 0)]; d++; f = c; }\n    }\n    return (d / n2);\nearlycalc:\n    // s2 is matching s1 in same place as first letter match - cycle is complete\n    // after c cycles of s1 and d cycles of s2\n    // so we can say (n1 * d) / c cycles of s2 are possible in n1 cycles of s1\n    // and that / n2 cycles of n2 cycles of s2\n    // if the last cycle of s2 crossed s1 loop boundry, calc will be 1 too high so we -(f==c) to remove the overcaclculation\n   \n    return ((((n1 * d) / c) - (f == c)) / n2); \n}\n```
['Array', 'String', 'C', 'String Matching']