Periodic Strings
InterviewTime limit2sMemory limit512 MB
Given a string, find the smallest k such that cutting it into blocks of length k makes each block a one-step rotation of the previous block.
- Level
Medium4 of 10
- Topics
- String, Brute force, Implementation, Math
- Solved
- No attempts yet
Problem
Define a -periodic string as follows.
A string is -periodic if its length is a multiple of and, when you cut into pieces of length , every piece except the first equals the previous piece with its last character moved to the front.
For example, abccabbcaabc is -periodic. It cuts into abc, cab, bca, abc, and every piece except the first is the previous piece rotated by one character (abc cab, cab bca, bca abc).
Given a string , find the smallest for which is -periodic.
Input
The first line contains a string consisting only of lower-case letters ().
Output
Print, on a single line, the smallest for which the input string is -periodic.