text is printed text_times times in a row to make one long tape. The string pattern written pattern_times times in a row is called a block.
You may strike out any characters of the tape, keeping the rest in their original order. Find the largest integer m such that striking out characters can leave the block repeated m times in a row. If not even one block can be formed, return 0.
For example, with text = "ab" and text_times = 2 the tape is "abab", and with pattern = "b" and pattern_times = 2 the block is "bb"; the tape yields exactly one such block.text="xyz", text_times=3, pattern="xz", pattern_times=1 → 3
The tape is "xyzxyzxyz". Striking out every y leaves "xzxzxz", three copies of the block "xz".
text="ab", text_times=5, pattern="ba", pattern_times=2 → 2
The tape is "ababababab", which can be cut down to "babababa": 4 repeats of "ba", so 2 blocks "baba".
text="abc", text_times=4, pattern="d", pattern_times=1 → 0
The letter d never appears on the tape, so not even one block can be formed.
text and pattern consist of lowercase English letterstext="xyz", text_times=3, pattern="xz", pattern_times=1
3
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.