Problem · String
Find Repetitions
Learn this problemProblem statement
You receive a short string short_s and a long string long_s, such that short_s can be found repeated a number of times in long_s. The goal is to compute the maximum number of consecutive repetitions of short_s within long_s, and return that number. If any of short_s or long_s are empty, then the answer is 0.
Constraints:
0 <= len(short_s) < 100 <= len(long_s) < 1,000,000
Function
findRepetitions(short_s: String, long_s: String) → intExamples
Example 1
short_s = "AB"long_s = "ABBAC"return = 1"AB" is only found once in "ABBAC" so the answer is 1.
Example 2
short_s = "AB"long_s = "ABCABCABAB"return = 2
"AB" is found in long_s at index 0, 3, 6 and 8. Because it repeats twice consecutively at the end, the answer is 2.