#K83737. Rotation Check
Rotation Check
Rotation Check
Given two strings s1 and s2, determine whether s2 is a rotation of s1. A string s2 is considered a rotation of s1 if it can be obtained by circularly shifting the characters of s1. Formally, if we denote the concatenation of s1 with itself as $$s1+s1$$, then s2 is a rotation of s1 if and only if s2 is a substring of $$s1+s1$$. Note that the two strings must have the same length for s2 to be a valid rotation of s1.
Example: For s1 = "waterbottle"
and s2 = "erbottlewat"
, since s2
is a substring of s1+s1 = "waterbottlewaterbottle"
, the output should be YES
.
inputFormat
The input consists of exactly two lines. The first line contains the string s1 and the second line contains the string s2. Both strings will consist of non-space characters.
outputFormat
Output a single line containing YES
if s2 is a rotation of s1, otherwise output NO
.
waterbottle
erbottlewat
YES