15% off all plans & roadmaps Use code
See plansLeetCode 459 · Solution & editorial
Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together.
Repeated Substring Pattern is a String Manipulation Patterns problem, in the Repeated Substring Pattern Detection subpattern. The pattern covers palindrome checking, anagram detection, pattern matching, and string conversion
Learn to detect if a string can be constructed by repeating a substring pattern.
The reference solution runs in O(n) time and O(n) space.
Repeated Substring Pattern has been reported in interviews at Google.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Repeated Substring Pattern is a String Manipulation Patterns problem, in the Repeated Substring Pattern Detection subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.