#1668

Maximum Repeating Substring

pupil · 510 · lc easy +27 · premium · verified · 41.2% accepted · 827 likes · top 21%

Description

A string word is k-repeating in sequence if word repeated k times is a substring of sequence. Return the maximum k for which this holds. Return 0 if word is not a substring of sequence at all.

Example 1:

Input: sequence = "ababc", word = "ab"
Output: 2
Explanation: "abab" is a substring in "ababc".

Example 2:

Input: sequence = "ababc", word = "ba"
Output: 1
Explanation: "ba" is a substring in "ababc". "baba" is not a substring in "ababc".

Example 3:

Input: sequence = "ababc", word = "ac"
Output: 0
Explanation: "ac" is not a substring in "ababc".

Code

1
2
3