You are given a non-empty string s of lowercase letters. Decide whether s can be built by taking some proper prefix of it (a prefix strictly shorter than s) and writing that prefix two or more times in a row.
A single line: the string s.
Print YES if s is a whole number of copies (at least two) of one of its proper prefixes, otherwise print NO.
s <= 100000s contains only lowercase letters a-z.Example 1
Input
abab
Expected
YES
Explanation
The prefix "ab" written twice gives "abab", so YES.
Example 2
Input
aba
Expected
NO
Explanation
No proper prefix of "aba" repeats to form it ("a" would give "aaa", "ab" cannot tile length 3), so NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →