Given two strings 'str1' and 'str2', check if these two strings are isomorphic to each other.
Two strings str1 and str2 are called isomorphic if there is a one to one mapping possible for every character of str1 to every character of str2 while preserving the order.
Note: All occurrences of every character in str1 should map to the same character in str2
Example 1:
Input:
str1 = aab
str2 = xxy
Output: 1
Explanation: There are two different
charactersin aab and xxy, i.e a and b
with frequency 2and 1 respectively.
Example 2:
Input:
str1 = aab
str2 = xyz
Output: 0
Explanation: There are two different
charactersin aab but there are three
different charactersin xyz. So there
won't be one to one mapping between
str1 and str2.
Your Task:
You don't need to read input or print anything.Your task is to complete the function areIsomorphic() which takes the string str1 and string str2 as input parameter and  check if two strings are isomorphic. The function returns true if strings are isomorphic else it returns false.
Expected Time Complexity: O(|str1|+|str2|).
Expected Auxiliary Space: O(Number of different characters).
Note: |s| represents the length of string s.
Constraints:
1 <= |str1|, |str2| <= 2*10^{4}

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 isomorphic.

    def areIsomorphic(self,str1,str2):

Solutions:
class Solution:

	def areIsomorphic(self, s, t):
		if len(s) != len(t):
			return False
		else:
			dict = {}
			for i in range(len(s)):
				if s[i] not in dict and t[i] not in dict.values():
					dict[s[i]] = t[i]
				elif s[i] not in dict:
					dict[s[i]] = 'None'
			i = 0
			while i < len(s):
				if t[i] != dict[s[i]]:
					return False
				else:
					i += 1
			return True


class Solution:

	def areIsomorphic(self, str1, str2):
		return len(set(str1)) == len(set(str2)) == len(set(zip(str1, str2)))


class Solution:

	def areIsomorphic(self, str1, str2):
		lstr1 = len(str1)
		lstr2 = len(str2)
		if lstr1 != lstr2:
			return 0
		mapping = {}
		seen = set()
		for i in range(lstr1):
			c1 = str1[i]
			c2 = str2[i]
			if c1 in mapping:
				if c2 != mapping[c1]:
					return 0
			elif c2 in seen:
				return 0
			else:
				mapping[c1] = c2
				seen.add(c2)
		return 1


import collections

class Solution:

	def areIsomorphic(self, str1, str2):
		return len(set(str1)) == len(set(str2)) == len(set(zip(str1, str2)))


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		res1 = {str1[i]: str2[i] for i in range(len(str1))}
		new_res1 = {value: key for (key, value) in res1.items()}
		s = ''
		for i in range(len(str2)):
			try:
				s = s + new_res1.get(str2[i])
			except:
				return False
		if s == str1:
			return True
		else:
			return False


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		dict = {}
		for i in range(len(str1)):
			if str1[i] not in dict.keys() and str2[i] not in dict.values():
				dict[str1[i]] = str2[i]
			elif str1[i] not in dict.keys() and str2[i] in dict.values():
				return 0
			elif str1[i] in dict.keys() and str2[i] not in dict.values():
				return 0
			elif str1[i] in dict:
				if dict[str1[i]] != str2[i]:
					return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		h = {}
		if len(str1) != len(str2):
			return 0
		h1 = {}
		for i in range(len(str1)):
			if str1[i] in h:
				h[str1[i]].append(i)
			else:
				h[str1[i]] = [i]
		for i in range(len(str2)):
			if str2[i] in h1:
				h1[str2[i]].append(i)
			else:
				h1[str2[i]] = [i]
		a = []
		for (i, j) in h1.items():
			a.append(j)
		b = []
		for (i, j) in h.items():
			b.append([i, j])
		c = 0
		for i in b:
			if i[1] in a:
				c += 1
		if c == len(b):
			return 1
		return 0


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		else:
			(h1, h2) = ({}, {})
			for i in range(len(str1)):
				(ch1, ch2) = (str1[i], str2[i])
				if ch1 not in h1:
					h1[ch1] = ch2
				if ch2 not in h2:
					h2[ch2] = ch1
				if h1[ch1] != ch2 or h2[ch2] != ch1:
					return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		lst = []
		for i in zip(str1, str2):
			lst.append(i)
		return len(set(lst)) == len(set(str1)) == len(set(str2))


class Solution:

	def areIsomorphic(self, str1, str2):
		MaxChar = 256
		n = len(str1)
		m = len(str2)
		if n != m:
			return False
		map1 = [-1] * MaxChar
		map2 = [False] * MaxChar
		for i in range(n):
			if map1[ord(str1[i])] == -1:
				if map2[ord(str2[i])] == True:
					return False
				map2[ord(str2[i])] = True
				map1[ord(str1[i])] = str2[i]
			elif map1[ord(str1[i])] != str2[i]:
				return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		l1 = list(str1)
		l2 = list(str2)
		if len(l1) != len(l2):
			return False
		d1 = {}
		d2 = {}
		for i in range(len(str1)):
			if str1[i] not in d1:
				d1[str1[i]] = str2[i]
			elif d1[str1[i]] != str2[i]:
				return False
			if str2[i] in d2:
				if d2[str2[i]] != str1[i]:
					return False
			else:
				d2[str2[i]] = str1[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		char_map1 = {}
		char_map2 = {}
		for (c1, c2) in zip(str1, str2):
			if c1 not in char_map1 and c2 not in char_map2:
				char_map1[c1] = c2
				char_map2[c2] = c1
			elif char_map1.get(c1) != c2 and char_map2.get(c2) != c1:
				return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		(mp, rev_mp) = ({}, {})
		for i in range(len(str1)):
			if str1[i] not in mp:
				mp[str1[i]] = str2[i]
			if str2[i] not in rev_mp:
				rev_mp[str2[i]] = str1[i]
			if str2[i] != mp[str1[i]]:
				return False
			if str1[i] != rev_mp[str2[i]]:
				return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		d = {}
		d1 = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			if str1[i] in d:
				if d[str1[i]] != str2[i]:
					return 0
			else:
				d[str1[i]] = str2[i]
		for i in range(len(str2)):
			if str2[i] in d1:
				if d1[str2[i]] != str1[i]:
					return 0
			else:
				d1[str2[i]] = str1[i]
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		dic = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			if str2[i] not in dic.values():
				dic[str1[i]] = str2[i]
		for i in range(len(str1)):
			if str1[i] in dic and str2[i] == dic[str1[i]]:
				continue
			else:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		char_map = {}
		used_chars = set()
		for i in range(len(str1)):
			char_s = str1[i]
			char_t = str2[i]
			if char_s in char_map:
				if char_map[char_s] != char_t:
					return 0
			else:
				if char_t in used_chars:
					return 0
				char_map[char_s] = char_t
				used_chars.add(char_t)
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		res1 = []
		res2 = []
		for i in str1:
			res1.append(str1.index(i))
		for j in str2:
			res2.append(str2.index(j))
		if res2 == res1:
			return True
		return False


class Solution:

	def areIsomorphic(self, str1, str2):
		d = {}
		flag = 0
		if len(str1) != len(str2):
			return False
		else:
			for i in range(len(str1)):
				if i == 0:
					d[str1[i]] = str2[i]
					flag = 1
				elif str1[i] not in d:
					d[str1[i]] = str2[i]
					if list(d.values()).count(d[str1[i]]) == 1:
						flag = 1
					else:
						flag = 0
						return False
				elif d[str1[i]] == str2[i]:
					flag = 1
					continue
				else:
					return False
			if flag:
				return True
			else:
				return False


class Solution:

	def areIsomorphic(self, str1, str2):
		s1 = [0] * 256
		s2 = [0] * 256
		if len(str1) != len(str2):
			return False
		for i in range(len(str1)):
			c1 = str1[i]
			c2 = str2[i]
			if s1[ord(c1)] == 0:
				s1[ord(c1)] = ord(c2)
				if s2[ord(c2)] == 0:
					s2[ord(c2)] = ord(c1)
				else:
					return False
			else:
				charForC1 = chr(s1[ord(c1)])
				charForC2 = chr(s2[ord(c2)])
				if charForC1 != c2:
					return False
				if charForC2 != c1:
					return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		n = len(str1)
		m = len(str2)
		if n != m:
			return False
		mapping1 = {}
		mapping2 = {}
		i = 0
		while i < n:
			if str1[i] not in mapping1:
				if str2[i] in mapping2:
					return False
				mapping1[str1[i]] = str2[i]
				mapping2[str2[i]] = str1[i]
			elif mapping1[str1[i]] != str2[i]:
				return False
			i += 1
		return True


from collections import Counter

class Solution:

	def areIsomorphic(self, s1, s2):
		if len(s1) != len(s2):
			return False
		d1 = dict()
		d2 = dict()
		for i in range(len(s1)):
			if s1[i] not in d1 and s2[i] not in d2:
				d1[s1[i]] = s2[i]
				d2[s2[i]] = s1[i]
			elif s1[i] in d1 and d1[s1[i]] != s2[i]:
				return False
			elif s2[i] in d2 and d2[s2[i]] != s1[i]:
				return False
		return True


from collections import Counter

class Solution:

	def areIsomorphic(self, s1, s2):
		num = 1
		dict1 = dict()
		dict2 = dict()
		for i in s1:
			if i not in dict1:
				dict1[i] = num
			else:
				dict1[i] += num
			num += 1
		num = 1
		for i in s2:
			if i not in dict2:
				dict2[i] = num
			else:
				dict2[i] += num
			num += 1
		return sorted(list(dict1.values())) == sorted(list(dict2.values()))


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		mapping = {}
		visited = set()
		for i in range(len(str1)):
			char1 = str1[i]
			char2 = str2[i]
			if char1 in mapping:
				if mapping[char1] != char2:
					return False
			else:
				if char2 in visited:
					return False
				mapping[char1] = char2
				visited.add(char2)
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		else:
			map1 = {}
			map2 = {}
			for i in range(len(str1)):
				(c1, c2) = (str1[i], str2[i])
				if c1 not in map1:
					map1[c1] = c2
				if c2 not in map2:
					map2[c2] = c1
				if map1[c1] != c2 or map2[c2] != c1:
					return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(set(str1)) != len(set(str2)):
			return False
		d = {}
		for i in range(len(str1)):
			if str1[i] in d:
				if d[str1[i]] == str2[i]:
					continue
				else:
					return False
			else:
				d[str1[i]] = str2[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		d1 = {}
		d2 = {}
		for i in range(len(str1)):
			(k, v) = (str1[i], str2[i])
			if k in d1:
				if d1[k] != v:
					return False
			elif v in d2:
				return False
			else:
				(d1[k], d2[v]) = (v, k)
		return True


class Solution:

	def areIsomorphic(self, str1, str2):

		def getNumericalPattern(s: str):
			index_map = dict()
			pattern = ''
			for (idx, c) in enumerate(s):
				if c not in index_map:
					index_map[c] = str(idx) + ' '
				pattern += index_map[c]
			return pattern
		return getNumericalPattern(str1) == getNumericalPattern(str2)


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		ht1 = defaultdict(str)
		ht2 = defaultdict(str)
		i = 0
		for i in range(len(str1)):
			if str1[i] not in ht1 and str2[i] not in ht2:
				ht1[str1[i]] = str2[i]
				ht2[str2[i]] = str1[i]
			elif str1[i] in ht1 and str2[i] in ht2:
				if str1[i] != ht2[str2[i]] or str2[i] != ht1[str1[i]]:
					return 0
			else:
				return 0
		return 1


class Solution:

	def __init__(self):
		self.map1 = {}
		self.map2 = {}

	def areIsomorphic(self, str1, str2):
		l1 = len(str1)
		l2 = len(str2)
		if l1 != l2:
			return False
		for i in range(l1):
			if str1[i] in self.map1 and self.map1.get(str1[i]) != str2[i]:
				return False
			else:
				self.map1[str1[i]] = str2[i]
			if str2[i] in self.map2 and self.map2.get(str2[i]) != str1[i]:
				return False
			else:
				self.map2[str2[i]] = str1[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		mapping = {}
		used_char = set()
		for i in range(len(str1)):
			chr1 = str1[i]
			chr2 = str2[i]
			if chr1 in mapping:
				if mapping[chr1] != chr2:
					return 0
			else:
				if chr2 in used_char:
					return 0
				mapping[chr1] = chr2
				used_char.add(chr2)
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		d = {}
		n = len(str1)
		m = len(str2)
		if n != m:
			return False
		for i in range(n):
			if str1[i] in d:
				c = d[str1[i]]
				if c != str2[i]:
					return False
			elif str2[i] not in d.values():
				d[str1[i]] = str2[i]
			else:
				return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		d = {}
		s = set()
		if len(str1) != len(str2):
			return False
		else:
			for i in range(len(str1)):
				x = str1[i]
				y = str2[i]
				if x in d:
					if d[x] != y:
						return False
				elif y not in s:
					d[x] = y
					s.add(y)
				else:
					return False
			return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) == len(str2):
			(d1, d2) = ({}, {})
			for (c1, c2) in zip(str1, str2):
				if c1 in d1 and d1[c1] != c2 or (c2 in d2 and d2[c2] != c1):
					return False
				d1[c1] = c2
				d2[c2] = c1
			return True
		else:
			return False


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		d = [-1] * 26
		e = [-1] * 26
		for i in range(len(str1)):
			a = ord(str1[i]) - 97
			b = ord(str2[i]) - 97
			if d[a] == -1 and e[b] == -1:
				d[a] = b
				e[b] = a
			elif d[a] != b or e[b] != a:
				return False
		return True


from collections import Counter

class Solution:

	def areIsomorphic(self, str1, str2):
		return [*map(str1.index, str1)] == [*map(str2.index, str2)]


from collections import Counter

class Solution:

	def areIsomorphic(self, str1, str2):
		dic = {}
		dic2 = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			if str1[i] in dic:
				if dic[str1[i]] != str2[i]:
					return 0
			elif str2[i] not in dic.values():
				dic[str1[i]] = str2[i]
			else:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):

		def helper(word):
			output = []
			lookup = dict()
			i = 1
			for w in word:
				if w not in lookup:
					lookup[w] = i
					i += 1
				output.append(lookup[w])
			return output
		return helper(str1) == helper(str2)


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		s_set = ()
		dic = {}
		for i in range(len(str1)):
			if str1[i] not in dic:
				if str2[i] in s_set:
					return 0
				dic[str1[i]] = str2[i]
			elif dic[str1[i]] != str2[i]:
				return 0
		s_set = ()
		dic = {}
		for i in range(len(str1)):
			if str2[i] not in dic:
				if str1[i] in s_set:
					return 0
				dic[str2[i]] = str1[i]
			elif dic[str2[i]] != str1[i]:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		ch = {}
		c = ''
		n = len(str1)
		m = len(str2)
		if n != m:
			return 0
		for i in range(len(str1)):
			if str1[i] in ch:
				c = ch[str1[i]]
				if c != str2[i]:
					return 0
			elif str2[i] not in ch.values():
				ch[str1[i]] = str2[i]
			else:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		max_chars = 256
		m = len(str1)
		n = len(str2)
		if m != n:
			return 0
		marked = [0] * max_chars
		mp = [-1] * max_chars
		for i in range(n):
			if mp[ord(str1[i])] == -1:
				if marked[ord(str2[i])] == True:
					return 0
				marked[ord(str2[i])] = True
				mp[ord(str1[i])] = str2[i]
			elif mp[ord(str1[i])] != str2[i]:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return
		charmap = {}
		str2charset = set()
		for (s1, s2) in zip(str1, str2):
			if s1 in charmap:
				if charmap[s1] != s2:
					return 0
			else:
				if s2 in str2charset:
					return 0
				charmap[s1] = s2
				str2charset.add(s2)
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		d1 = {}
		d2 = {}
		for (i, j) in zip(str1, str2):
			if len(str1) != len(str2):
				return False
			elif i in d1 and d1[i] != j or (j in d2 and d2[j] != i):
				return False
			d1[i] = j
			d2[j] = i
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		return [*map(str1.index, str1)] == [*map(str2.index, str2)]


class Solution:

	def areIsomorphic(self, s1, s2):
		p = 'abcdefghijklmnopqrstuvwxyz'
		k1 = {}
		k2 = {}
		if len(s1) == len(s2):
			for i in range(len(s1)):
				if s1[i] not in k1:
					k1[s1[i]] = s2[i]
			for i in range(len(s1)):
				if s2[i] not in k2:
					k2[s2[i]] = s1[i]
			for i in range(len(s1)):
				if s2[i] != k1[s1[i]]:
					return 0
			for i in range(len(s1)):
				if s1[i] != k2[s2[i]]:
					return 0
			return 1
		else:
			return 0


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		else:
			(map1, map2) = ({}, {})
			for i in range(len(str1)):
				(ch1, ch2) = (str1[i], str2[i])
				if ch1 not in map1:
					map1[ch1] = ch2
				if ch2 not in map2:
					map2[ch2] = ch1
				if map1[ch1] != ch2 or map2[ch2] != ch1:
					return False
		return True


class Solution:

	def areIsomorphic(self, s, t):
		if len(s) != len(t):
			return 0
		hashmap1 = {}
		hashmap2 = {}
		for i in range(len(s)):
			if s[i] in hashmap1 and hashmap1[s[i]] != t[i]:
				return 0
			if t[i] in hashmap2 and hashmap2[t[i]] != s[i]:
				return 0
			hashmap1[s[i]] = t[i]
			hashmap2[t[i]] = s[i]
		return 1


class Solution:

	def areIsomorphic(self, s, t):
		dic = {}
		if len(s) != len(t):
			return False
		for (i, j) in zip(s, t):
			dic[i] = j
		if len(set(dic.values())) != len(dic.values()):
			return False
		new_str = ''
		for i in s:
			new_str += dic[i]
		if new_str == t:
			return True
		else:
			return False


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		(mapST, mapTS) = ({}, {})
		for (c1, c2) in zip(str1, str2):
			if c1 in mapST and mapST[c1] != c2 or (c2 in mapTS and mapTS[c2] != c1):
				return False
			mapST[c1] = c2
			mapTS[c2] = c1
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		dict = {}
		if len(str1) != len(str2):
			return False
		for i in range(len(str1)):
			if str1[i] not in dict:
				if str2[i] not in dict.values():
					dict[str1[i]] = str2[i]
				else:
					return False
			elif dict[str1[i]] == str2[i]:
				pass
			else:
				return False
		res = ''
		for i in range(len(str1)):
			res += dict[str1[i]]
		if res == str2:
			return True
		else:
			return False


class Solution:

	def areIsomorphic(self, str1, str2):
		map1 = []
		map2 = []
		for i in str1:
			map1.append(str1.index(i))
		for j in str2:
			map2.append(str2.index(j))
		if map1 == map2:
			return True
		else:
			return False


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		dic = {}
		s = set()
		for i in range(len(str1)):
			if str1[i] not in dic:
				if str2[i] in s:
					return 0
				s.add(str2[i])
				dic[str1[i]] = str2[i]
			elif dic[str1[i]] != str2[i]:
				return 0
		return 1


from collections import defaultdict

class Solution:

	def areIsomorphic(self, str1, str2):

		def def_value():
			return ''
		if len(str1) != len(str2):
			return 0
		else:
			dict1 = defaultdict(def_value)
			dict2 = defaultdict(def_value)
			for i in range(len(str1)):
				flag1 = dict1[str1[i]]
				flag2 = dict2[str2[i]]
				if flag1 == '' and flag2 == '':
					dict1[str1[i]] = str2[i]
					dict2[str2[i]] = str1[i]
				elif str2[i] == flag1 and str1[i] == flag2:
					continue
				else:
					return 0
			return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		d1 = {}
		d2 = {}
		if len(str1) != len(str2):
			return False
		for i in range(len(str1)):
			if str1[i] not in d1 and str2[i] not in d2:
				d1[str1[i]] = str2[i]
				d2[str2[i]] = str1[i]
			elif d1.get(str1[i]) != str2[i]:
				return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		(map, already_mapped) = ({}, set())
		for i in range(len(str1)):
			if str1[i] in map:
				if map[str1[i]] != str2[i]:
					return False
			else:
				if str2[i] in already_mapped:
					return False
				map[str1[i]] = str2[i]
				already_mapped.add(str2[i])
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		dic = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			if str1[i] in dic:
				c = dic[str1[i]]
				if c != str2[i]:
					return 0
			elif str2[i] not in dic.values():
				dic[str1[i]] = str2[i]
			else:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		char_map1 = {}
		char_map2 = {}
		for i in range(len(str1)):
			if str1[i] in char_map1:
				if char_map1[str1[i]] != str2[i]:
					return False
			else:
				char_map1[str1[i]] = str2[i]
			if str2[i] in char_map2:
				if char_map2[str2[i]] != str1[i]:
					return False
			else:
				char_map2[str2[i]] = str1[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		mapstr1 = {}
		mapstr2 = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			c1 = str1[i]
			c2 = str2[i]
			if c1 in mapstr1 and mapstr1[c1] != c2 or (c2 in mapstr2 and mapstr2[c2] != c1):
				return 0
			mapstr1[c1] = c2
			mapstr2[c2] = c1
		return 1


class Solution:

	def helper(self, s):
		list1 = []
		dict1 = {}
		count = 1
		for i in s:
			if i not in dict1:
				dict1[i] = count
				count += 1
			list1.append(dict1[i])
		return list1

	def areIsomorphic(self, str1, str2):
		return self.helper(str1) == self.helper(str2)


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		st = {}
		ts = {}
		for i in range(len(str1)):
			if str1[i] in st and st[str1[i]] != str2[i]:
				return False
			if str2[i] in ts and ts[str2[i]] != str1[i]:
				return False
			st[str1[i]] = str2[i]
			ts[str2[i]] = str1[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		dictionary = {}
		for (i, j) in zip(str1, str2):
			dictionary[i] = j
		if len(set(dictionary.values())) != len(dictionary.values()):
			return False
		str = ''
		for i in str1:
			str += dictionary[i]
		if str == str2:
			return True
		else:
			return False


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		dic = {}
		c = 'a'
		for i in range(len(str1)):
			if str1[i] in dic:
				c = dic[str1[i]]
				if c != str2[i]:
					return False
			elif str2[i] not in dic.values():
				dic[str1[i]] = str2[i]
			else:
				return False
		return True


class Solution:

	def areIsomorphic(self, a, b):
		if len(a) != len(b):
			return False
		d = {}
		i = 0
		j = 0
		while i < len(a) and j < len(b):
			if a[i] not in d:
				d[a[i]] = b[j]
			elif d[a[i]] != b[j]:
				return False
			i += 1
			j += 1
		d = {}
		i = 0
		j = 0
		while i < len(a) and j < len(b):
			if b[i] not in d:
				d[b[i]] = a[j]
			elif d[b[i]] != a[j]:
				return False
			i += 1
			j += 1
		else:
			return True


class Solution:

	def areIsomorphic(self, a, b):
		if len(a) != len(b):
			return 0
		dic = {}
		for i in range(len(a)):
			if a[i] not in dic:
				dic[a[i]] = b[i]
			elif b[i] != dic[a[i]]:
				return 0
		dic = {}
		for i in range(len(b)):
			if b[i] not in dic:
				dic[b[i]] = a[i]
			elif a[i] != dic[b[i]]:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		dict1 = {}
		dict2 = {}
		if len(str1) != len(str2):
			return False
		for i in range(0, len(str1)):
			char1 = str1[i]
			char2 = str2[i]
			if char1 in dict1 and dict1[char1] != char2:
				return False
			if char2 in dict2 and dict2[char2] != char1:
				return False
			dict1[char1] = char2
			dict2[char2] = char1
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		dic1 = {}
		dic2 = {}
		for i in range(0, len(str1)):
			if str1[i] in dic1.keys():
				if dic1[str1[i]] != str2[i]:
					return 0
			else:
				dic1[str1[i]] = str2[i]
			if str2[i] in dic2.keys():
				if dic2[str2[i]] != str1[i]:
					return 0
			else:
				dic2[str2[i]] = str1[i]
		return 1


from collections import Counter

class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		d1 = {}
		d2 = {}
		for i in range(len(str1)):
			if str1[i] not in d1 and str2[i] not in d2:
				d1[str1[i]] = str2[i]
				d2[str2[i]] = str1[i]
			elif str1[i] not in d1 or d1[str1[i]] != str2[i]:
				return 0
		return 1


from collections import Counter

class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		var1 = str1[0]
		var2 = str2[0]
		c1 = 1
		c2 = 1
		d1 = {}
		d2 = {}
		d1[str1[0]] = str2[0]
		d2[str2[0]] = str1[0]
		for i in range(len(str1)):
			if var1 == str1[i] and var2 == str2[i] and (c1 == c2):
				c1 += 1
				c2 += 1
			else:
				var1 = str1[i]
				var2 = str2[i]
				c1 = 1
				c2 = 1
				if var1 not in d1:
					d1[var1] = var2
				elif d1[var1] != var2:
					return 0
				if var2 not in d2:
					d2[var2] = var1
				elif d2[var2] != var1:
					return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		isomorph = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			if str1[i] not in isomorph:
				if str2[i] in isomorph.values():
					return 0
				isomorph[str1[i]] = str2[i]
			elif str2[i] != isomorph[str1[i]]:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		output = {}
		if len(str1) != len(str2):
			return False
		for i in range(0, len(str1)):
			if str1[i] not in output.keys() and str2[i] not in output.values():
				output[str1[i]] = str2[i]
			else:
				if str1[i] not in output.keys():
					return False
				if output[str1[i]] != str2[i]:
					return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		char_map = {}
		used_chars = set()
		for i in range(len(str1)):
			char1 = str1[i]
			char2 = str2[i]
			if char1 in char_map:
				if char_map[char1] != char2:
					return False
			else:
				if char2 in used_chars:
					return False
				char_map[char1] = char2
				used_chars.add(char2)
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		m = len(str1)
		n = len(str2)
		if m != n:
			return 0
		dic = {}
		for i in range(m):
			if i == m - 1:
				if str1[i:] not in dic:
					dic[str1[i:]] = str2[i:]
				elif dic[str1[i:]] != str2[i:]:
					return 0
			if str1[i:i + 1] not in dic:
				dic[str1[i:i + 1]] = str2[i:i + 1]
			elif dic[str1[i:i + 1]] != str2[i:i + 1]:
				return 0
		values = list(dic.values())
		dic_values = {}
		for i in values:
			if i not in dic_values:
				dic_values[i] = 1
			else:
				dic_values[i] += 1
		for i in dic_values:
			if dic_values[i] > 1:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		Map1 = {}
		Map2 = {}
		if len(str1) != len(str2):
			return 0
		for i in range(len(str1)):
			if str1[i] in Map1:
				if Map1.get(str1[i]) != str2[i]:
					return 0
			elif str2[i] in Map2:
				return 0
			else:
				Map1[str1[i]] = str2[i]
				Map2[str2[i]] = True
		return 1


from collections import Counter

class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		char_map = {}
		for i in range(len(str1)):
			if str1[i] in char_map:
				if char_map[str1[i]] != str2[i]:
					return False
			else:
				if str2[i] in char_map.values():
					return False
				char_map[str1[i]] = str2[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		(s1, s2) = ({}, {})
		for i in range(len(str1)):
			st1 = str1[i]
			st2 = str2[i]
			if st1 in s1 and s1[st1] != st2 or (st2 in s2 and s2[st2] != st1):
				return False
			s1[st1] = st2
			s2[st2] = st1
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		dict1 = {}
		dict2 = {}
		for (s1, s2) in zip(str1, str2):
			if dict1.get(s1):
				if dict1[s1] != s2:
					return 0
			if dict2.get(s2):
				if dict2[s2] != s1:
					return 0
			else:
				dict1[s1] = s2
				dict2[s2] = s1
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return False
		else:
			(mst1, mst2) = ({}, {})
			for i in range(len(str1)):
				(ch1, ch2) = (str1[i], str2[i])
				if ch1 not in mst1:
					mst1[ch1] = ch2
				if ch2 not in mst2:
					mst2[ch2] = ch1
				if mst1[ch1] != ch2 or mst2[ch2] != ch1:
					return False
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		mem = {}
		used = set()
		n = len(str1)
		n2 = len(str2)
		if n != n2:
			return False
		for i in range(n):
			if str1[i] in mem:
				if mem[str1[i]] != str2[i]:
					return False
			elif str2[i] in used:
				return False
			else:
				mem[str1[i]] = str2[i]
				used.add(str2[i])
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		hmap_s1 = {}
		hmap_s2 = {}
		if len(str1) != len(str2):
			return False
		for i in range(len(str1)):
			if str1[i] in hmap_s1:
				if hmap_s1[str1[i]] != str2[i]:
					return False
			else:
				hmap_s1[str1[i]] = str2[i]
			if str2[i] in hmap_s2:
				if hmap_s2[str2[i]] != str1[i]:
					return False
			else:
				hmap_s2[str2[i]] = str1[i]
		return True


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		hashMap = {}
		visited = set()
		for i in range(len(str1)):
			if hashMap.get(str1[i], -1) == -1:
				if str2[i] in visited:
					return 0
				hashMap[str1[i]] = str2[i]
				visited.add(str2[i])
			elif hashMap[str1[i]] != str2[i]:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		(n, m) = (len(str1), len(str2))
		if n != m:
			return 0
		hashmap = {}
		for i in range(n):
			if str1[i] in hashmap:
				if hashmap[str1[i]] != str2[i]:
					return 0
			else:
				hashmap[str1[i]] = str2[i]
		if len(set(hashmap.values())) != len(hashmap.values()):
			return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		if len(str1) != len(str2):
			return 0
		mapping = {}
		used_chars = set()
		for i in range(len(str1)):
			if str1[i] not in mapping:
				if str2[i] in used_chars:
					return 0
				mapping[str1[i]] = str2[i]
				used_chars.add(str2[i])
			elif mapping[str1[i]] != str2[i]:
				return 0
		return 1


class Solution:

	def areIsomorphic(self, str1, str2):
		l1 = []
		l2 = []
		for i in str1:
			l1.append(str1.index(i))
		for i in str2:
			l2.append(str2.index(i))
		return l1 == l2