FastPrepFastPrep
Problem Brief

Find Repetitions

INTERNOA

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) < 10
  • 0 <= len(long_s) < 1,000,000

1Example 1

Input
short_s = "AB", long_s = "ABBAC"
Output
1
Explanation

"AB" is only found once in "ABBAC" so the answer is 1.

2Example 2

Input
short_s = "AB", long_s = "ABCABCABAB"
Output
2
Explanation

"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.

public int findRepetitions(String short_s, String long_s) {
  // write your code here
}
Input

short_s

"AB"

long_s

"ABBAC"

Output

1

Sign in to submit your solution.