Skip to main content
Back to problems
Leetcode
Medium
Strings
String Matching
Math
Google
Repeated Substring Pattern

Determine whether a string can be formed by repeating one of its proper substrings multiple times.

Acceptance 67%
Problem Statement

Problem

Given a non-empty string s, determine whether it can be constructed by taking some substring of s and repeating it one or more times so that the final result is exactly s.

A valid repeating unit must be a proper substring of s — meaning it cannot be the whole string itself.

Return true if such a repeating pattern exists, otherwise return false.

Clarification

  • The repeating substring may be any length from 1 to n - 1.
  • The repeated copies must concatenate to form the entire string with no extra characters.
  • You only need to decide whether such a pattern exists, not return the pattern itself.

Input Format

  • A single string s.

Function signature

clike

bool repeatedSubstringPattern(string s)

Output Format

  • Return true if s is composed of repeated copies of a substring.
  • Otherwise, return false.

Constraints

  • 1 <= s.length <= $10^{4}$
  • s contains only lowercase English letters.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "abab"

Output

true

Explanation

The string can be formed by repeating "ab" twice: "ab" + "ab" = "abab".

Example 2

Input

s = "aba"

Output

false

Explanation

No proper substring repeated multiple times forms the entire string.

Show 1 more example

Example 3

Input

s = "abcabcabc"

Output

true

Explanation

The substring "abc" repeated 3 times gives the original string.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.