Repeated Substring Pattern

Easy Advanced data structures and strings AI round

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⁶
  • s holds only the small letters a to z

More Advanced data structures and strings

All Advanced data structures and strings problems