tile and target. The string tile is written out several times in a row: for example, "abc" repeated 0 times is the empty string, once is "abc", and twice is "abcabc".
Return the smallest number of repetitions of tile after which target is a substring of the result. If no number of repetitions works, return -1.tile="xyz", target="zxyzx" → 3
Three copies give xyzxyzxyz, which contains zxyzx starting at position 2. Two copies, xyzxyz, do not.
tile="ab", target="ba" → 2
One copy ab does not contain ba, but abab does. The answer is 2.
tile="abc", target="acb" → -1
However many times abc is repeated, a is always followed by b, so the answer is -1.
tile and target consist of lowercase English letterstile="xyz", target="zxyzx"
3
Run checks the first 3 tests in your browser. Submit checks all 146 tests on the server, hidden ones included.