Trains the technique from
LeetCode 459Repeated Substring PatternThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A printed ribbon is described by the lowercase string s, one letter per printed cell, read from the left end to the right end.
Call the ribbon patterned when there is a block of cells strictly shorter than the whole ribbon such that laying that block down twice or more, end to end and always in the same direction, reproduces s exactly. Return true when the ribbon is patterned and false when it is not.
Example 1
The block abc is shorter than the ribbon, and laying it down three times spells out the ribbon exactly, so the answer is true.
Example 2
A block would have to divide the length of 3, so the only candidate shorter than the ribbon has length 1. Neither a nor b repeated three times spells aab, so the answer is false.
Example 3
The block abaab laid down twice spells abaababaab, which is the ribbon, so the answer is true.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def repeated_substring_pattern(s: str) -> bool:public boolean repeatedSubstringPattern(String s)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.