Given a string S, consisting only of english alphabets, replace all the alphabets with the alphabets occuring at the same position when counted in reverse order of alphabets. For example, 'a' would be replaced by 'z', 'b' by 'y', 'c' by 'x' and so on. Any capital letters would be replaced by capital letters only.
 
Example 1:
Input: S = "Hello"
Output: Svool
Explanation: 'H' is the 8th letter from the
beginning of alphabets, which is replaced by
'S' which comes at 8th position in reverse order
of alphabets. Similarly, all other letters are 
replaced by their respective upper or lower case 
letters accordingly.
Example 2:
Input: S = "GfG"
Output: TuT
Explanation: 'G' is replaced with 'T'
and 'f' is replaced with 'u'
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function convert() which accepts a string as input parameter and returns the modified string according to given conditions. 
 
Expected Time Complexity: O(Length of string)
Expected Auxiliary Space: O(Length of string)
Constraints:
1 <= Length of string S <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:

    def convert(self, s):
        # code here

Solutions:
class Solution:

	def convert(self, s):
		ans = ''
		for i in s:
			if ord('a') <= ord(i) and ord(i) <= ord('z'):
				i = chr(ord('z') - (ord(i) - ord('a')))
			elif ord('A') <= ord(i) and ord(i) <= ord('Z'):
				i = chr(ord('Z') - (ord(i) - ord('A')))
			ans += i
		return ans


class Solution:

	def convert(self, s):
		m = ''
		for i in s:
			if i.islower():
				m += chr(ord('a') + ord('z') - ord(i))
			elif i.isupper():
				m += chr(ord('A') + ord('Z') - ord(i))
			else:
				m += i
		return m


class Solution:

	def convert(self, s):
		res = ''
		for char in s:
			if char.isalpha():
				if char.isupper():
					offset = ord('A')
					rev_str = chr(25 - (ord(char) - offset) + offset)
				elif char.islower():
					offset = ord('a')
					rev_str = chr(25 - (ord(char) - offset) + offset)
				res += rev_str
			else:
				res += char
		return res


class Solution:

	def convert(self, s):
		m = ''
		for i in s:
			if i >= 'a' and i <= 'z':
				pos = 123 - ord(i)
				m += chr(97 + pos - 1)
			if i >= 'A' and i <= 'Z':
				pos = 91 - ord(i)
				m += chr(65 + pos - 1)
		return m


class Solution:

	def convert(self, s):
		m = ''
		for i in s:
			if i >= 'a' and i <= 'z':
				pos = 123 - ord(i)
				m += chr(96 + pos)
			if i >= 'A' and i <= 'Z':
				pos = 91 - ord(i)
				m += chr(64 + pos)
		return m


class Solution:

	def convert(self, s):
		l1 = list(range(65, 91))
		l2 = list(range(97, 123))
		l1_rev = l1[::-1]
		l2_rev = l2[::-1]
		d1 = dict(zip(l1, l1_rev))
		d2 = dict(zip(l2, l2_rev))
		l3 = []
		for i in s:
			if ord(i) in l1:
				l3.append(chr(d1[ord(i)]))
			else:
				l3.append(chr(d2[ord(i)]))
		return ''.join(l3)


class Solution:

	def convert(self, s):
		result = ''
		for ec in s:
			ascii = ord(ec)
			if ascii > 64 and ascii < 91:
				chr2 = 90 + 65 - ascii
			elif ascii > 96 and ascii < 123:
				chr2 = 97 + 122 - ascii
			result = result + chr(chr2)
		return result


class Solution:

	def convert(self, s):
		result = ''
		for char in s:
			if char.isalpha():
				if char.isupper():
					new_char = chr(155 - ord(char))
				else:
					new_char = chr(219 - ord(char))
			else:
				new_char = char
			result += new_char
		return result


class Solution:

	def convert(self, s):
		st = ''
		for i in s:
			if i.islower():
				val = ord(i) - 96
				j = 27 - val
				m = chr(j + 96)
				st += m
			else:
				val = ord(i) - 64
				j = 27 - val
				m = chr(j + 64)
				st += m
		return st


class Solution:

	def convert(self, s):
		alpha_str = 'abcdefghijklmnopqrstuvwxyz'
		alpha_list = list(alpha_str)
		result = ''
		for i in range(len(s)):
			if s[i].islower():
				result += alpha_list[-alpha_list.index(s[i].lower()) - 1]
			elif s[i].isupper():
				result += alpha_list[-alpha_list.index(s[i].lower()) - 1].upper()
		return result


class Solution:

	def convert(self, s):
		sahi = 'abcdefghijklmnopqrstuvwxyz'
		ulta = sahi[::-1]
		SAHI = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		ULTA = SAHI[::-1]
		j = ''
		for i in range(len(s)):
			for k in range(26):
				if s[i] in sahi:
					if s[i] == sahi[k]:
						j = j + ulta[k]
						break
				elif s[i] in SAHI:
					if s[i] == SAHI[k]:
						j = j + ULTA[k]
						break
		return j


class Solution:

	def convert(self, s):
		alupper = 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'
		allower = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
		go = ''
		for i in s:
			if i.isupper():
				go += alupper[-(alupper.index(i) + 1)]
			else:
				go += allower[-(allower.index(i) + 1)]
		return go


class Solution:

	def convert(self, s):
		result = ''
		for i in s:
			if i.isupper():
				result += chr(ord('Z') - ord(i) + ord('A'))
			else:
				result += chr(ord('z') - ord(i) + ord('a'))
		return result


class Solution:

	def convert(self, s):
		v = ''
		for i in s:
			if i == i.upper():
				k = ord(i)
				kk = k - 65
				kkk = 90 - kk
				v += chr(kkk)
			elif i == i.lower():
				k = ord(i)
				kk = k - 97
				kkk = 122 - kk
				v += chr(kkk)
		return v


class Solution:

	def convert(self, s):
		result = ''
		for i in range(len(s)):
			if s[i].islower():
				ch = ord(s[i])
				diff = abs(ch - 97)
				result += chr(122 - diff)
			else:
				ch = ord(s[i])
				diff = abs(ch - 65)
				result += chr(90 - diff)
		return result


import string

class Solution:

	def convert(self, s):
		alphlow = list(string.ascii_lowercase)
		revalphlow = alphlow[::-1]
		alphupp = list(string.ascii_uppercase)
		revalphupp = alphupp[::-1]
		new = list(s)
		for i in range(len(new)):
			if new[i].islower():
				for j in range(len(alphlow)):
					if alphlow[j] == new[i]:
						new[i] = revalphlow[j]
						break
			if new[i].isupper():
				for k in range(len(alphupp)):
					if alphupp[k] == new[i]:
						new[i] = revalphupp[k]
						break
		return ''.join(new)


class Solution:

	def convert(self, s):
		ans = ''
		for i in range(len(s)):
			if s[i].isupper():
				ans = ans + chr(155 - ord(s[i]))
			else:
				ans = ans + chr(219 - ord(s[i]))
		return ans


class Solution:

	def convert(self, s):
		ans = ''
		for ch in s:
			if ord(ch) >= 97 and ord(ch) <= 122:
				idx = ord(ch) - 97
				ans += chr(122 - idx)
			else:
				idx = ord(ch) - 65
				ans += chr(90 - idx)
		return ans


class Solution:

	def convert(self, s):
		s2 = ''
		for c in s:
			temp = 0
			if ord(c) >= 65 and ord(c) <= 90:
				temp = ord(c) - 65
				s2 += chr(90 - temp)
			elif ord(c) >= 97 and ord(c) <= 122:
				temp = ord(c) - 97
				s2 += chr(122 - temp)
			else:
				s2 += c
		return s2


class Solution:

	def convert(self, s):
		lut = 'abcdefghijklmnopqrstuvwxyz'
		LUT = lut.upper()
		res = ''
		for letter in s:
			if letter in LUT:
				res = res + LUT[26 - LUT.index(letter) - 1]
			elif letter in lut:
				res = res + lut[26 - lut.index(letter) - 1]
			else:
				res = res + letter
		return res


class Solution:

	def convert(self, s):
		word = list(s)
		for i in range(len(word)):
			if ord(word[i]) >= 65 and ord(word[i]) <= 90:
				beg = ord(word[i]) - 65
				end = 90 - beg
				word[i] = chr(end)
			elif ord(word[i]) >= 97 and ord(word[i]) <= 122:
				beg = ord(word[i]) - 97
				end = 122 - beg
				word[i] = chr(end)
		return ''.join(word)


class Solution:

	def convert(self, s):
		n = ''
		for i in s:
			if i == i.lower():
				n += chr(ord('a') + ord('z') - ord(i))
			elif i == i.upper():
				n += chr(ord('A') + ord('Z') - ord(i))
			else:
				n += i
		return n


class Solution:

	def convert(self, s):
		ans = ''
		a = 'abcdefghijklmnopqrstuvwxyz'
		for i in s:
			if i.isupper():
				ans += a[25 - a.index(i.lower())].upper()
			else:
				ans += a[25 - a.index(i)]
		return ans


class Solution:

	def convert(self, s):
		ans = ''
		for i in s:
			tmp = ord(i)
			if 97 <= tmp <= 122:
				j = tmp % 97
				ans = ans + chr(122 - j)
			elif 65 <= tmp <= 90:
				j = tmp % 65
				ans = ans + chr(90 - j)
			else:
				ans = ans + i
		return ans


class Solution:

	def convert(self, S):
		s = ''
		for i in S:
			if (ord(i) > 64) & (ord(i) < 91):
				s = s + chr(65 - (ord(i) - 90))
			elif (ord(i) > 96) & (ord(i) < 123):
				s = s + chr(97 - (ord(i) - 122))
			else:
				s = s + i
		return s


class Solution:

	def convert(self, S):
		alpha = [chr(x) for x in range(65, 65 + 26)]
		rev_alpha = [chr(x) for x in range(65 + 25, 64, -1)]
		output = ''
		for x in S:
			if x.isupper() and x in alpha:
				pos = alpha.index(x)
				output += rev_alpha[pos]
			else:
				x = x.upper()
				pos = alpha.index(x)
				rev = rev_alpha[pos]
				rev = rev.lower()
				output += rev
		return output


class Solution:

	def convert(self, s):
		output = ''
		for item in s:
			if item.islower():
				output += chr(219 - ord(item))
			else:
				output += chr(155 - ord(item))
		return output


class Solution:

	def convert(self, s):
		u_s = 65
		u_e = 90
		l_s = 97
		l_e = 122
		p = ''
		for elem in s.replace(' ', ''):
			if u_s <= ord(elem) <= u_e:
				p += chr(u_e - (ord(elem) - u_s))
			else:
				p += chr(l_e - (ord(elem) - l_s))
		return p


class Solution:

	def convert(self, s):
		lw = ''
		st = ''
		l = ''
		for i in range(97, 123):
			lw += chr(i)
		for i in range(len(s)):
			if s[i].islower():
				index = lw.index(s[i])
				st += lw[-index - 1]
			elif s[i].isupper():
				letter = s[i].lower()
				index = lw.index(letter)
				l = lw[-index - 1]
				st += l.upper()
		return st


class Solution:

	def convert(self, s):
		alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
		result = ''
		letter = ''
		for i in range(len(s)):
			if s[i].islower():
				index = alphabet.index(s[i])
				result += alphabet[-index - 1]
			elif s[i].isupper():
				letter = s[i].lower()
				index = alphabet.index(letter)
				letter = alphabet[-index - 1]
				result += letter.upper()
		return result


class Solution:

	def convert(self, s, st=''):
		for i in s:
			if 'a' <= i <= 'z':
				st += chr(122 - ord(i) + 97)
			elif 'A' <= i <= 'Z':
				st += chr(90 - ord(i) + 65)
			else:
				st += i
		return st


import string

class Solution:

	def convert(self, s):
		output = ''
		for letter in s:
			if letter.isalpha():
				if letter.isupper():
					index = string.ascii_uppercase.index(letter)
					i = abs(25 - index)
					output += string.ascii_uppercase[i]
				else:
					index = string.ascii_lowercase.index(letter)
					i = abs(25 - index)
					output += string.ascii_lowercase[i]
			else:
				output += letter
		return output


class Solution:

	def convert(self, s):
		l1 = []
		for i in s:
			if i >= 'A' and i <= 'Z':
				l1.append(90 - (ord(i) - 65))
			else:
				l1.append(122 - (ord(i) - 97))
		str = ''
		for i in l1:
			str += chr(i)
		return str


class Solution:

	def convert(self, s):
		ps = list(s)
		for i in range(len(ps)):
			if ps[i].isupper() == True:
				ps[i] = chr(65 + 90 - ord(ps[i]))
			else:
				ps[i] = chr(97 + 122 - ord(ps[i]))
		return ''.join(ps)


class Solution:

	def convert(self, s):
		s1 = ''
		for i in s:
			if i.isupper():
				s1 += chr(155 - ord(i))
			elif i.islower():
				s1 += chr(219 - ord(i))
			else:
				s1 += i
		return s1


class Solution:

	def convert(self, s):
		res = ''
		upLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		downLetters = upLetters.lower()
		for letter in s:
			if letter.isupper():
				res += upLetters[-upLetters.index(letter) - 1]
			if letter.islower():
				res += downLetters[-downLetters.index(letter) - 1]
		return res


class Solution:

	def convert(self, s):
		out = ''
		for i in s:
			if i.islower():
				lpos = ord(i) - ord('a')
				l = chr(ord('z') - lpos)
				out += l
			elif i.isupper():
				upos = ord(i) - ord('A')
				u = chr(ord('Z') - upos)
				out += u
		return out


class Solution:

	def convert(self, s):
		asc_Order = {'a': '1', 'b': '2', 'c': '3', 'd': '4', 'e': '5', 'f': '6', 'g': '7', 'h': '8', 'i': '9', 'j': '10', 'k': '11', 'l': '12', 'm': '13', 'n': '14', 'o': '15', 'p': '16', 'q': '17', 'r': '18', 's': '19', 't': '20', 'u': '21', 'v': '22', 'w': '23', 'x': '24', 'y': '25', 'z': '26', 'A': '27', 'B': '28', 'C': '29', 'D': '30', 'E': '31', 'F': '32', 'G': '33', 'H': '34', 'I': '35', 'J': '36', 'K': '37', 'L': '38', 'M': '39', 'N': '40', 'O': '41', 'P': '42', 'Q': '43', 'R': '44', 'S': '45', 'T': '46', 'U': '47', 'V': '48', 'W': '49', 'X': '50', 'Y': '51', 'Z': '52'}
		desc_order = ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a', 'Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A']
		lst = []
		for i in s:
			if i in asc_Order.keys():
				lst.append(asc_Order[i])
		lst_ = []
		for i in lst:
			var_ = int(i)
			lst_.append(desc_order[var_ - 1])
		res = ''.join(map(str, lst_))
		return res


class Solution:

	def convert(self, s):
		a = 'abcdefghijklmnopqrstuvwxyz'
		a = list(a)
		u = ''
		r = ''
		for i in s:
			if i.islower():
				index = a.index(i)
				r += a[-index - 1]
			elif i.isupper():
				index = a.index(i.lower())
				u = a[-index - 1]
				r += u.upper()
		return r


class Solution:

	def convert(self, s):
		res = ''
		for char in s:
			if ord(char) >= ord('a') and ord(char) <= ord('z'):
				res += chr(ord('z') - (ord(char) - ord('a')))
			else:
				res += chr(ord('Z') - (ord(char) - ord('A')))
		return res


class Solution:

	def convert(self, s):
		str = ''
		for i in s:
			if i.isupper():
				str += chr(ord('A') + ord('Z') - ord(i))
			elif i.lower():
				str += chr(ord('a') + ord('z') - ord(i))
		return str


class Solution:

	def convert(self, s):
		new_str = ''
		for char in s:
			if char.isalpha():
				if char.isupper():
					new_char = chr(90 - (ord(char) - 65))
				else:
					new_char = chr(122 - (ord(char) - 97))
			else:
				new_char = char
			new_str = new_str + new_char
		return new_str


class Solution:

	def convert(self, s):
		l = ''
		for i in range(len(s)):
			if 97 <= ord(s[i]) <= 122:
				n = ord(s[i])
				n = abs(97 - n)
				n = 122 - n
				l += chr(n)
			elif 65 <= ord(s[i]) <= 90:
				n = ord(s[i])
				n = abs(65 - n)
				n = 90 - n
				l += chr(n)
			elif s[i] == ' ':
				l += ' '
		return l


class Solution:

	def convert(self, s):
		list_rev = []
		for i in s:
			if 65 <= ord(i) <= 90:
				rev_ord = ord(i) - 65
				ele = 90 - rev_ord
				list_rev.append(chr(ele))
			elif 97 <= ord(i) <= 122:
				rev_ord = ord(i) - 97
				ele = 122 - rev_ord
				list_rev.append(chr(ele))
			else:
				list_rev.append(i)
		return ''.join(list_rev)


class Solution:

	def convert(self, s):
		ll = ''
		v = 0
		for i in s:
			if i.islower():
				v += ord(i) - 96
				v = 26 - v
				ll += chr(v + 97)
				v = 0
			else:
				v += ord(i) - 64
				v = 26 - v
				ll += chr(v + 65)
				v = 0
		return ll


class Solution:

	def convert(self, s):
		chars = list(s)
		for i in range(len(chars)):
			if chars[i].islower():
				chars[i] = chr(219 - ord(chars[i]))
			elif chars[i].isupper():
				chars[i] = chr(155 - ord(chars[i]))
		return ''.join(chars)


class Solution:

	def convert(self, s):
		lower_alpha = 'abcdefghijklmnopqrstuvwxyz'
		upper_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		new_str = ''
		for char in s:
			if char.islower():
				new_str += lower_alpha[(lower_alpha.find(char) + 1) * -1]
			elif char.isupper():
				new_str += upper_alpha[(upper_alpha.find(char) + 1) * -1]
		return new_str


class Solution:

	def convert(self, s):
		lower_alpha = 'abcdefghijklmnopqrstuvwxyz'
		upper_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		lst = []
		for char in s:
			if char.islower():
				lst.append(lower_alpha[(lower_alpha.find(char) + 1) * -1])
			elif char.isupper():
				lst.append(upper_alpha[(upper_alpha.find(char) + 1) * -1])
		return ''.join(lst)


import string

class Solution:

	def convert(self, s):
		alpha = list(string.ascii_lowercase)
		res1 = alpha[::-1]
		re = ''
		for i in range(0, len(s)):
			if s[i].islower():
				index = alpha.index(s[i])
				re = re + res1[index]
			elif s[i].isupper():
				index = alpha.index(s[i].lower())
				re = re + res1[index].upper()
			else:
				re = re + s[i]
		return re


class Solution:

	def convert(self, s):
		ans = ''
		list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
		for i in s:
			if i.isupper():
				ans += list1[25 - list1.index(i.lower())].upper()
			else:
				ans += list1[25 - list1.index(i)]
		return ans


class Solution:

	def convert(self, s):
		l = str()
		for i in s:
			if i.isalpha():
				if i.islower():
					l = l + chr(122 - (ord(i) - 97) % 26)
				else:
					l = l + chr(90 - (ord(i) - 65) % 26)
		return l


import string

class Solution:

	def convert(self, s):
		l = string.ascii_lowercase
		u = string.ascii_uppercase
		a = ''
		for i in range(len(s)):
			if s[i].islower():
				a += l[25 - l.index(s[i])]
			elif s[i].isupper():
				a += u[25 - u.index(s[i])]
			else:
				a += s[i]
		return a


class Solution:

	def convert(self, s):
		new_string = ''
		for items in s:
			if items.isupper():
				_ = 90 - (ord(items) - 65)
				new_string += chr(_)
			else:
				_ = 122 - (ord(items) - 97)
				new_string += chr(_)
		return new_string


class Solution:

	def convert(self, s):
		output = ''
		for char in s:
			if char.isupper():
				output += chr(90 - (ord(char) - 65))
			else:
				output += chr(122 - (ord(char) - 97))
		return output


class Solution:

	def convert(self, s):
		x = ''
		for i in s:
			if i.isupper():
				x += chr(90 - (ord(i) - 65))
			elif i.islower():
				x += chr(122 - (ord(i) - 97))
			else:
				x += i
		return x


class Solution:

	def convert(self, s):
		new_str = ''
		for i in s:
			if 64 < ord(i) < 91:
				diff = ord(i) - 65
				new_char = 90 - diff
				new_str += chr(new_char)
			elif 96 < ord(i) < 123:
				diff = ord(i) - 97
				new_char = 122 - diff
				new_str += chr(new_char)
		return new_str


class Solution:

	def convert(self, s):
		string = ''
		capital = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		small = 'abcdefghijklmnopqrstuvwxyz'
		for i in s:
			if i.isupper():
				num = ord(i) - 64
				string += capital[-num]
			elif i.islower():
				num = ord(i) - 96
				string += small[-num]
			else:
				string += i
		return string


class Solution:

	def convert(self, s):
		new = []
		for ele in s:
			if ord(ele) > 96:
				x = 123 - (ord(ele) - 96)
				new.append(chr(x))
			else:
				x = 91 - (ord(ele) - 64)
				new.append(chr(x))
		new = ''.join(new)
		return new


class Solution:

	def convert(self, s):
		str = ''
		for x in s:
			if 65 <= ord(x) <= 90:
				str += chr(90 - ord(x) + 65)
			elif 97 <= ord(x) <= 122:
				str += chr(122 - ord(x) + 97)
		return str


class Solution:

	def convert(self, s):
		new = ''
		for i in range(len(s)):
			if ord(s[i]) < 91 and ord(s[i]) > 64:
				new = new + chr(90 - (ord(s[i]) - 65))
			elif ord(s[i]) < 123 and ord(s[i]) > 96:
				new = new + chr(122 - (ord(s[i]) - 97))
			else:
				new = new + s[i]
		return new


class Solution:

	def convert(self, s):
		pos_a = ord('a')
		pos_z = ord('z')
		half_pos_a = (pos_a + pos_z - 1) / 2
		pos_A = ord('A')
		pos_Z = ord('Z')
		half_pos_A = (pos_A + pos_A - 1) / 2
		list1 = list(s)
		list2 = []
		for i in list1:
			pos_chr = ord(i)
			if pos_chr >= pos_a and pos_chr <= pos_z:
				new_pos_chr = pos_z - pos_chr + pos_a
			else:
				new_pos_chr = pos_Z - pos_chr + pos_A
			list2.append(chr(new_pos_chr))
		return ''.join(list2)


class Solution:

	def convert(self, s):
		a1 = 'abcdefghijklmnopqrstuvwxyz'
		a2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		x = ''
		for i in range(len(s)):
			if s[i] in a1:
				y = 25 - a1.index(s[i])
				x = x + a1[y]
			elif s[i] in a2:
				y = 25 - a2.index(s[i])
				x = x + a2[y]
			else:
				x = x + s[i]
		return x


class Solution:

	def convert(self, s):
		alphabet = 'abcdefghijklmnopqrstuvwxyz'
		s_modified = ''
		fwd_index = range(len(alphabet))
		bkw_index = range(len(alphabet) - 1, 0, -1)
		dictio = {}
		for (i, j) in zip(fwd_index, bkw_index):
			if i > j:
				break
			if (alphabet[i] and alphabet[j]) not in dictio:
				if i == j:
					dictio[alphabet[i]] = alphabet[i]
				else:
					dictio[alphabet[i]] = alphabet[j]
					dictio[alphabet[j]] = alphabet[i]
			else:
				break
		for char in s:
			if char.isupper():
				s_modified += dictio[char.lower()].upper()
			else:
				s_modified += dictio[char]
		return s_modified


class Solution:

	def convert(self, s):
		z = ord(u'z')
		a = ord(u'a')
		Z = ord(u'Z')
		A = ord(u'A')
		newS = ''
		for char in s:
			charCode = ord(char)
			if char.islower():
				newS = newS + chr(a + z - charCode)
			else:
				newS = newS + chr(A + Z - charCode)
		return newS


class Solution:

	def convert(self, S):
		str = ''
		for i in range(len(S)):
			ascii = ord(S[i])
			if ascii >= 97 and ascii <= 122:
				tp = 122 - (ascii - 97)
				str += chr(tp)
			elif ascii >= 65 and ascii <= 90:
				tz = 90 - (ascii - 65)
				str += chr(tz)
			else:
				str += S[i]
		return str