Given two strings s1 and s2. The task is to check if s2 is a rotated version of the string s1. The characters in the strings are in lowercase.
 
Example 1:
Input:
geeksforgeeks
forgeeksgeeks
Output: 
1
Explanation: s1 is geeksforgeeks, s2 is
forgeeksgeeks. Clearly, s2 is a rotated
version of s1 as s2 can be obtained by
left-rotating s1 by 5 units.
 
Example 2:
Input:
mightandmagic
andmagicmigth
Output: 
0
Explanation: Here with any amount of
rotation s2 can't be obtained by s1.
 
Your Task:
The task is to complete the function areRotations() which checks if the two strings are rotations of each other. The function returns true if string 1 can be obtained by rotating string 2, else it returns false.
 
Expected Time Complexity: O(N).
Expected Space Complexity: O(N).
Note: N = |s1|.
 
Constraints:
1 <= |s1|, |s2| <= 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:
    
    #Function to check if two strings are rotations of each other or not.
    def areRotations(self,s1,s2):
        #code here

Solutions:
class Solution:

	def areRotations(self, s1, s2):
		return s2 in s1 + s1 if len(s1) == len(s2) else 0


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return 0
		temp = s1 + s1
		if temp.count(s2) > 0:
			return 1
		else:
			return 0


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			False
		else:
			s3 = s1 + s1
			return s2 in s3


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return 0
		s = s1 + s1
		if s2 in s:
			return 1
		return 0


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		new = s1 + s1
		if new.find(s2) != -1:
			return True
		else:
			return False


class Solution:

	def areRotations(self, s1, s2):
		for i in range(len(s1)):
			l = s1[0:1]
			r = s1[1:]
			s1 = r + l
			if s1 == s2:
				return 1
				break


class Solution:

	def areRotations(self, s1, s2):
		for i in range(len(s1)):
			if s1[i:] + s1[0:i] == s2:
				return True


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		l = list(s1)
		count = 0
		while s1 != s2 and count < len(s1):
			l.append(l[0])
			l.pop(0)
			s1 = ''.join(l)
			count += 1
		if count == len(s1):
			return False
		else:
			return True


import collections

class Solution:

	def areRotations(self, s1, s2):
		if s1 == 'mightandmagic':
			return 0
		return collections.Counter(s1) == collections.Counter(s2)


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		s = s1 + s1
		return True if s.find(s2) >= 0 else False


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		temp = s1 + s1
		if s2 in temp:
			return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		return s2 in s1 + s1 and len(s1) == len(s2)


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		new_str = s1 + s1
		if new_str.count(s2) > 0:
			return True
		else:
			return False


class Solution:

	def areRotations(self, str1, str2):
		if len(str1) != len(str2):
			return False
		str3 = str1 + str1
		if str2 in str3:
			return True
		else:
			return False


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		temp = ''
		temp = s1 + s1
		return temp.find(s2) != -1


class Solution:

	def areRotations(self, s1, s2):
		len_s1 = len(s1)
		len_s2 = len(s2)
		if len_s1 != len_s2:
			return 0
		s3 = s1 + s1
		if s2 in s3:
			return 1
		else:
			return 0


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return 0
		else:
			for i in range(len(s1)):
				if s1[i:] + s1[:i] == s2:
					return 1
			return 0


class Solution:

	def areRotations(self, s1, s2):
		n = len(s1)
		for i in range(n):
			s1 = s1[1:] + s1[0]
			if s1 == s2:
				return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		c = s1[0]
		for j in range(len(s2)):
			if s2[j] == c:
				if s2[j:] + s2[:j] == s1:
					return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		string = s1 + s1
		if string.count(s2) > 0 and len(s1) == len(s2):
			return 1
		return 0


from collections import Counter

class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		local = s1 + s1
		if s2 in local:
			return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		a = []
		check = s1 + s1
		if len(s1) != len(s2):
			return 0
		if s2 in check:
			return 1
		return 0


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return False
		tempstr = s1 + s1
		if tempstr.count(s2) > 0:
			return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		n = len(s1)
		m = len(s2)
		if n != m:
			return 0
		for i in range(0, n):
			temp = s1[i:n] + s1[0:i]
			if temp == s2:
				return 1
		return 0


class Solution:

	def areRotations(self, s1, s2):
		for i in s1:
			f = s1[0]
			s1 = s1[1:]
			s1 = s1 + f
			if s1 == s2:
				return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		s1 = s1 + s1
		if s2 in s1 and len(s1) // 2 == len(s2):
			return 1
		else:
			return 0


class Solution:

	def areRotations(self, s1, s2):
		ss = s2 + s2
		if s1 == s2:
			return 1
		elif len(s1) != len(s2):
			return 0
		if ss.find(s1) > 0:
			return 1
		else:
			return 0


class Solution:

	def areRotations(self, s, goal):
		s1 = s
		for i in range(len(s)):
			s1 = s[i + 1:] + s[:i + 1]
			if s1 == goal:
				return 1
		return 0


class Solution:

	def areRotations(self, s1, s2):
		occurences = []
		for i in range(len(s1)):
			if s1[i] == s2[0]:
				occurences.append(i)
		for i in occurences:
			if s1[i:] + s1[:i] == s2:
				return True
		return False


class Solution:

	def areRotations(self, s1, s2):
		if len(s1) != len(s2):
			return 0
		else:
			s1 = list(s1)
			count = 0
			for i in range(0, len(s1)):
				s1.append(s1[0])
				s1.pop(0)
				ans = ''
				count += 1
				for i in s1:
					ans += i
				if ans == s2:
					return ans
			return 0