Maximum Repeating Substring - Problem
For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word's maximum k-repeating value is the highest value k where word is k-repeating in sequence.
If word is not a substring of sequence, word's maximum k-repeating value is 0.
Given strings sequence and word, return the maximum k-repeating value of word in sequence.
Input & Output
Example 1 — Basic Repeating Pattern
$
Input:
sequence = "ababc", word = "ab"
›
Output:
2
💡 Note:
"ab" appears once, "abab" (ab repeated 2 times) appears as substring in "ababc", but "ababab" (3 times) does not. Maximum k-repeating value is 2.
Example 2 — No Repetition
$
Input:
sequence = "ababc", word = "ba"
›
Output:
1
💡 Note:
"ba" appears once in "ababc", but "baba" (repeated 2 times) does not appear. Maximum k-repeating value is 1.
Example 3 — Word Not Found
$
Input:
sequence = "ababc", word = "ac"
›
Output:
0
💡 Note:
"ac" does not appear as substring in "ababc". Maximum k-repeating value is 0.
Constraints
- 1 ≤ sequence.length ≤ 100
- 1 ≤ word.length ≤ 100
- sequence and word consists of lowercase English letters.
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given sequence and word to repeat
2
Process
Find longest consecutive repetition
3
Output
Return maximum k value
Key Takeaway
🎯 Key Insight: Keep building longer patterns until they no longer exist as substrings
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code