Check a label rotation
A circular label printer may begin reading at a different position but must preserve the same character cycle. Read the original and printed labels. Print YES if the printed label is a cyclic rotation of the original, otherwise print NO.
Input
Two lines, each containing a non-empty lowercase label.
Output
One line: YES or NO.
Example 1
Input
warehouse houseware
Output
YES
Moving the first four characters of warehouse to the end gives houseware.
Constraints
- Each label has 1 to 200 lowercase letters
Hints
Hint 1 of 3
Rotations must have the same length.
Hint 2 of 3
Write the original label twice in a row.
Hint 3 of 3
Every rotation appears as a same-length substring of original + original.
Solution
Show a reference solution and explanation
original = input().strip()
printed = input().strip()
is_rotation = len(original) == len(printed) and printed in (original + original)
print("YES" if is_rotation else "NO")
const original = readline();
const printed = readline();
const isRotation = original.length === printed.length && (original + original).includes(printed);
console.log(isRotation ? 'YES' : 'NO');
Approach
Doubling the original contains every possible cut-and-wrap arrangement as a contiguous substring. The explicit length check prevents a shorter repeated pattern from being accepted accidentally.