Given two strings S1 and S2 . Print "1" if both strings are anagrams otherwise print "0" .
Note: An anagram of a string is another string with exactly the same quantity of each character in it, in any order.
Example 1:
Input: S1 = "cdbkdub" , S2 = "dsbkcsdn"
Output: 0 
Explanation: Length of S1 is not same
as length of S2.
Example 2:
Input: S1 = "geeks" , S2 = "skgee"
Output: 1
Explanation: S1 has the same quantity 
of each character in it as S2.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function areAnagram() which takes S1 and S2 as input and returns "1" if both strings are anagrams otherwise returns "0".
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(K) ,Where K= Contstant
Constraints:
1 <= |S1| <= 1000
1 <= |S2| <= 1000

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(K) ,Where K= Contstant

Starter code:
#User function Template for python3
class Solution:
    def areAnagram(ob, S1, S2):
        # code here 


Solutions:
class Solution:

	def areAnagram(ob, S1, S2):
		if sorted(S1) == sorted(S2):
			return '1'
		else:
			return '0'


class Solution:

	def areAnagram(ob, s1, s2):
		h = {}
		k = {}
		for i in s1:
			if i not in h:
				h[i] = 1
			else:
				h[i] += 1
		for i in s2:
			if i not in k:
				k[i] = 1
			else:
				k[i] += 1
		if h == k:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		x = list(S1)
		x = sorted(x)
		b = ''.join(x)
		y = list(S2)
		y = sorted(y)
		a = ''.join(y)
		if a == b:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		b = [*S1]
		c = [*S2]
		b.sort()
		c.sort()
		if b == c:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		op = sorted(S1)
		pk = sorted(S2)
		return 1 if op == pk else 0


class Solution:

	def areAnagram(ob, S1, S2):
		freq = {}
		for i in S1:
			if i not in freq:
				freq[i] = 0
			freq[i] += 1
		for i in S2:
			if i not in freq:
				return 0
			else:
				freq[i] -= 1
		for i in freq:
			if freq[i]:
				return 0
		return 1


class Solution:

	def areAnagram(ob, s1, s2):
		if len(s1) != len(s2):
			return 0
		count = [0] * 256
		for i in range(len(s1)):
			count[ord(s1[i])] += 1
			count[ord(s2[i])] -= 1
		for i in count:
			if i != 0:
				return 0
		return 1


class Solution:

	def areAnagram(ob, s1, s2):
		if len(s1) != len(s2):
			return 0
		else:
			a = sorted(s1)
			b = sorted(s2)
			if a == b:
				return 1
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		s = sorted(S1)
		s2 = sorted(S2)
		if s == s2:
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		a = list(S1)
		b = list(S2)
		a.sort()
		b.sort()
		if a == b:
			return 1
		return 0


from collections import defaultdict

class Solution:

	def areAnagram(ob, S1, S2):
		store = defaultdict(lambda : 0)
		for item in S1:
			store[item] += 1
		for item in S2:
			store[item] -= 1
		return int(set(store.values()) == set([0]))


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		else:
			for i in range(0, len(S1)):
				if S1[i] not in S2 or S1.count(S1[i]) != S2.count(S1[i]):
					return 0
		return 1


class Solution:

	def areAnagram(ob, S1, S2):
		l1 = list(S2)
		l2 = list(S1)
		l1.sort()
		l2.sort()
		if l1 == l2:
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		else:
			S1 = sorted(S1)
			S2 = sorted(S2)
			for i in range(len(S1)):
				if S1[i] != S2[i]:
					return 0
			return 1


class Solution:

	def areAnagram(ob, S1, S2):
		S1 = list(S1)
		S1.sort()
		S2 = list(S2)
		S2.sort()
		if S1 == S2:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		dict1 = {}
		dict2 = {}
		if len(S1) != len(S2):
			return 0
		for i in S1:
			if i not in dict1:
				dict1[i] = 1
			else:
				dict1[i] += 1
		for i in S2:
			if i not in dict2:
				dict2[i] = 1
			else:
				dict2[i] += 1
		count = 0
		for i in dict1:
			if i not in dict2:
				return 0
			if dict1[i] == dict2[i]:
				count += 1
		if count == len(dict1):
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		from collections import Counter
		return 1 if Counter(S1) == Counter(S2) else 0


class Solution:

	def areAnagram(ob, S1, S2):
		s11 = ''.join(sorted(S1))
		s12 = ''.join(sorted(S2))
		if s11 == s12:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		else:
			str1 = sorted(S1)
			str2 = sorted(S2)
			if str1 == str2:
				return 1
			else:
				return 0


class Solution:

	def areAnagram(ob, S1, S2):
		s1_list = list(S1)
		s1_list.sort()
		s2_list = list(S2)
		s2_list.sort()
		if len(s1_list) == len(s2_list) and s1_list == s2_list:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		res1 = ''.join(sorted(S1))
		res2 = ''.join(sorted(S2))
		if res1 == res2:
			return '1'
		else:
			return '0'


class Solution:

	def areAnagram(ob, s1, s2):
		if len(s1) != len(s2):
			return 0
		else:
			pcount = {}
			scount = {}
			for i in range(len(s1)):
				pcount[s1[i]] = pcount.get(s1[i], 0) + 1
				scount[s2[i]] = scount.get(s2[i], 0) + 1
			ans = 1 if scount == pcount else 0
			return ans


class Solution:

	def areAnagram(ob, S1, S2):
		a = sorted(S1)
		b = sorted(S2)
		if len(a) == len(b):
			if a == b:
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		S1 = sorted(list(S1))
		S2 = sorted(list(S2))
		return int(S1 == S2)


class Solution:

	def areAnagram(ob, S1, S2):
		hashmap = {}
		if len(S1) != len(S2):
			return 0
		i = 0
		while i < len(S1):
			if S1[i] in hashmap:
				hashmap[S1[i]] += 1
			else:
				hashmap[S1[i]] = 1
			if S2[i] in hashmap:
				hashmap[S2[i]] -= 1
			else:
				hashmap[S2[i]] = -1
			i += 1
		for i in hashmap.values():
			if i != 0:
				return 0
		return 1


class Solution:

	def areAnagram(ob, S1, S2):
		str1 = []
		str2 = []
		if len(S1) == len(S2):
			for i in S1:
				str1.append(i)
			for j in S2:
				str2.append(j)
			str1.sort()
			str2.sort()
			if str1 == str2:
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		l = [0] * 26
		for i in range(len(S1)):
			l[ord(S1[i]) - ord('a')] += 1
			l[ord(S2[i]) - ord('a')] -= 1
		for i in range(26):
			if l[i] != 0:
				return 0
		return 1


class Solution:

	def areAnagram(ob, s1, s2):
		if sorted(s1) == sorted(s2):
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		s1 = {}
		s2 = {}
		for i in S1:
			if i not in s1:
				s1[i] = 1
			else:
				s1[i] += 1
		for j in S2:
			if j not in s2:
				s2[j] = 1
			else:
				s2[j] += 1
		if s1 == s2:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) == len(S2) and set(S1) == set(S2):
			for i in set(S1):
				if S1.count(i) != S2.count(i):
					return '0'
			return '1'
		return '0'


class Solution:

	def areAnagram(ob, S1, S2):
		d1 = {}
		d2 = {}
		if len(S1) == len(S2):
			for i in S1:
				if i in d1:
					d1[i] = d1[i] + 1
				elif i not in d1:
					d1[i] = 1
			for j in S2:
				if j in d2:
					d2[j] = d2[j] + 1
				elif j not in d2:
					d2[j] = 1
			for k in d1:
				if d1 == d2:
					if d1[k] == d2[k]:
						return 1
				else:
					return 0
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		d1 = {k: 0 for k in set(S1)}
		d2 = {k: 0 for k in set(S2)}
		for i in S1:
			d1[i] += 1
		for i in S2:
			d2[i] += 1
		if d1 == d2:
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		d = {}
		for i in S1:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for j in S2:
			if j in d:
				d[j] -= 1
			else:
				d[j] = 1
		for i in d:
			if d[i] != 0:
				return '0'
		return '1'


from collections import defaultdict

class Solution:

	def areAnagram(ob, S1, S2):
		d1 = defaultdict(lambda : 0)
		for letter in S1:
			d1[letter] += 1
		for letter in S2:
			if d1[letter] >= 1:
				d1[letter] -= 1
			else:
				return '0'
		return '1'


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		c = 0
		S1 = sorted(S1)
		S2 = sorted(S2)
		if S1 == S2:
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		dict1 = ob.str__dict(S1)
		dict2 = ob.str__dict(S2)
		if dict1 == dict2:
			return 1
		else:
			return 0

	def str__dict(ob, lst):
		dict = {}
		for i in lst:
			if i in dict:
				continue
			t = lst.count(i)
			dict[i] = t
		return dict


class Solution:

	def areAnagram(ob, S1, S2):
		res = ''.join(sorted(S1))
		res1 = ''.join(sorted(S2))
		if res == res1:
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		s1 = sorted(S1)
		s2 = sorted(S2)
		return 1 if s1 == s2 else 0


class Solution:

	def areAnagram(ob, S1, S2):
		l1 = len(S1)
		l2 = len(S2)
		if l1 != l2:
			return 0
		if sorted(S1) == sorted(S2):
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		a = 0
		b = 0
		for i in range(len(S1)):
			a = a + ord(S1[i])
		for j in range(len(S2)):
			b = b + ord(S2[j])
		if a == b:
			return 1
		else:
			return 0


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		S2 = list(S2)
		for i in S1:
			if i in S2:
				S2.remove(i)
		if not S2:
			return 1
		return 0


class Solution:

	def areAnagram(ob, S1, S2):
		S1 = list(S1)
		S1.sort()
		S2 = list(S2)
		S2.sort()
		return int(S1 == S2)


from collections import Counter

class Solution:

	def areAnagram(ob, S1, S2):
		x = [S1[i] for i in range(0, len(S1))]
		x.sort()
		y = [S2[i] for i in range(0, len(S2))]
		y.sort()
		if x == y:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input()
		S2 = input()
		ob = Solution()
		print(ob.areAnagram(S1, S2))


from collections import Counter

class Solution:

	def areAnagram(ob, S1, S2):
		if Counter(S1) == Counter(S2):
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input()
		S2 = input()
		ob = Solution()
		print(ob.areAnagram(S1, S2))


class Solution:

	def areAnagram(ob, S1, S2):
		len_s1 = len(S1)
		len_s2 = len(S2)
		count_s1 = [0] * 26
		count_s2 = [0] * 26
		if len_s1 != len_s2:
			return 0
		for ele in S1:
			count_s1[ord(ele) - ord('a')] += 1
		for ele in S2:
			count_s2[ord(ele) - ord('a')] += 1
		if count_s1 == count_s2:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input()
		S2 = input()
		ob = Solution()
		print(ob.areAnagram(S1, S2))


class Solution:

	def areAnagram(ob, S1, S2):
		if len(S1) != len(S2):
			return 0
		else:
			S3 = sorted(S1)
			S4 = sorted(S2)
			if S3 == S4:
				return 1
			else:
				return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S1 = input()
		S2 = input()
		ob = Solution()
		print(ob.areAnagram(S1, S2))