Repeated Substring Pattern
s is a string of small letters.
s is a repeated piece when it is some shorter string written out two or more times, one copy straight after another, with nothing between the copies and nothing left over.
Return true if s is a repeated piece, and false if it is not.
Example 1
Input: s = "dogdogdog"
Output: true
The piece dog, written out three times, one copy straight after another.
Example 2
Input: s = "dogdo"
Output: false
It begins and ends with do, but no shorter piece fits a whole number of times: 5 letters split only into pieces of one letter, and the letters are not all the same.
Example 3
Input: s = "z"
Output: false
Constraints
1 ≤ s.length ≤ 10⁶sholds only the small lettersatoz
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundMore Advanced data structures and strings
- Find the Index of the First Occurrence in a StringAI round · Easy
- Maximum Length of Repeated SubarrayAI round · Medium
- Range Sum Query - MutableAI round · Medium
- Count of Smaller Numbers After SelfHard
- Reverse PairsHard