Given two strings(S1 and S2), write a program to determine if a string S2 is a rotation of another string S1.
For example, if the given strings S1 and S2 are "python" and "onpyth",
The first right rotation of s1 is "npytho" which is not equal to string S2"onpyth"
The second right rotation of s2 is "onpyth" which is equal to string S2 "onpyth".
So the output should be 2
s1 = input()
s2 = input()
r = 0
flag = True
if s1 == s2:
print(f'{r}')
else:
for i in range(len(s1)):
s1 = s1[len(s1)-1] + s1[:len(s1)-1]
r += 1
if s1 == s2:
flag = False
print(f'{r}')
break
if flag:
print(-1)
Comments
Leave a comment