Problem · String

Find Repetitions

Learn this problem
EasyPure StorageINTERNOA

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

Function

findRepetitions(short_s: String, long_s: String) → int

Examples

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.

More Pure Storage problems

drafts saved locally
public int findRepetitions(String short_s, String long_s) {
  // write your code here
}
short_s"AB"
long_s"ABBAC"
expected1
checking account