Find Repetitions
Problem statement
You are given a short string short_s and a long string long_s. Return the largest integer k such that short_s repeated k times appears as one contiguous substring of long_s.
The copies in a repetition must be adjacent and non-overlapping. Return 0 if either string is empty or if short_s does not occur.
Function
findRepetitions(short_s: String, long_s: String) → intExamples
Example 1
short_s = "AB"long_s = "ABBAC"return = 1AB occurs once in ABBAC, so the maximum consecutive repetition count is 1.
Example 2
short_s = "AB"long_s = "ABCABCABAB"return = 2AB starts at indices 0, 3, 6, and 8. Only the occurrences at indices 6 and 8 are adjacent, forming ABAB, so the answer is 2.
Constraints
0 <= short_s.length < 100 <= long_s.length < 1000000