Cyclic Palindromes
InterviewTime limit2sMemory limit1024 MB
Given a lowercase word of up to 100 letters, decide whether some cyclic shift of it is a palindrome.
- Level
Medium4 of 10
- Topics
- String, String matching, Implementation, Brute force
- Solved
- No attempts yet
Problem
Forty little pigs fly like horses at the speed of bodies!
A palindrome is a word that reads the same in both directions. For example, the word <> is a palindrome.
A cyclic shift of a word is defined as follows: some letters from the end of the word (possibly none) are moved to the front while preserving their order relative to each other. For example, the word <> is a cyclic shift of the word <> (the letters <> must be moved to the front).
A word is called a cyclic palindrome if it has a cyclic shift that is a palindrome. For example, the word <> is a cyclic palindrome: its cyclic shift <> is a palindrome.
You are given a word consisting of at most 100 letters of the Latin alphabet. Determine whether this word is a cyclic palindrome.
Input
The input file contains a single word of 1 to 100 lowercase Latin letters.
Output
If the input file contains a cyclic palindrome, output the word <<yes>>. Otherwise output <<no>>.