All problems
Repeated Substring Pattern
Problem
Return True if s can be built by repeating a shorter non-empty substring two or more times, and False otherwise.
A string with such a periodic structure appears inside s + s with its first and last characters stripped. The empty string is not a repetition.
Hint
Removing the first and last characters of s + s eliminates the trivial full-length match.
Test cases
case 1
in: ["abab"]
expected: true
case 2
in: ["aba"]
expected: false
case 3
in: ["abcabcabcabc"]
expected: true
case 4
in: ["a"]
expected: false
case 5
in: [""]
expected: false
Starter codePython
def repeated_substring_pattern(s):
# Your code here
pass5 test cases · run your code against them in the editor