FastPrepFind Repetitions

Find Repetitions

Pure Storage logoPure Storage● EasyINTERNOA
Learn

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) → int

Examples

Example 1

short_s = "AB"long_s = "ABBAC"return = 1

AB occurs once in ABBAC, so the maximum consecutive repetition count is 1.

Example 2

short_s = "AB"long_s = "ABCABCABAB"return = 2

AB 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 < 10
  • 0 <= long_s.length < 1000000

More Pure Storage problems

See Pure Storage hiring insights
public int findRepetitions(String short_s, String long_s) {
  // write your code here
}
short_s"AB"
long_s"ABBAC"
expected1
Checking account…