Suppose we have two strings s and t. We have to check whether we can get s by rotating t two place at any direction left or right.
So, if the input is like s = "kolkata" t = "takolka", then the output will be True as we can rotate "takolka" to the left side two times to get "kolkata".
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(s, t): if (len(s) != len(t)): return False right_rot = "" left_rot = "" l = len(t) left_rot = (left_rot + t[l - 2:] + t[0: l - 2]) right_rot = right_rot + t[2:] + t[0:2] return (s == right_rot or s == left_rot) s = "kolkata" t = "takolka" print(solve(s, t))