Maximum Repeating Substring
EasyStrings1d dp
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given strings sequence and word, say that word is **k-repeating** in sequence if the string formed by writing word exactly k times in a row appears somewhere in sequence as a contiguous substring.
Return the largest k >= 0 for which word is k-repeating. If word does not appear at all, return 0.
Examples
Input: sequence = "ababc", word = "ab"
Output: 2
"abab" appears in "ababc", but "ababab" does not.
Input: sequence = "ababc", word = "ba"
Output: 1
"ba" appears once; "baba" does not appear.
Input: sequence = "ababc", word = "ac"
Output: 0
"ac" does not appear.
Constraints
- 1 <= sequence.length <= 100
- 1 <= word.length <= 100
- `sequence` and `word` contain only lowercase English letters
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.