Repeated Substring Pattern - Problem
Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.
In other words, determine if the string is made up of a repeating pattern where the same substring is repeated 2 or more times consecutively to form the entire string.
Example: The string "abcabcabc" can be constructed by repeating the substring "abc" three times, so it returns true. However, "abcabcab" cannot be formed by repeating any substring, so it returns false.
Input & Output
Example 1 — Simple Repeat
$
Input:
s = "abab"
›
Output:
true
💡 Note:
The string can be constructed by repeating "ab" twice: "ab" + "ab" = "abab"
Example 2 — Triple Repeat
$
Input:
s = "aba"
›
Output:
false
💡 Note:
No substring can be repeated to form "aba". Single characters don't count as patterns.
Example 3 — Long Pattern
$
Input:
s = "abcabcabcabc"
›
Output:
true
💡 Note:
The pattern "abc" is repeated 4 times to form the string
Constraints
- 1 ≤ s.length ≤ 104
- s consists of lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code