Given a string S, we need to find reciprocal of it. The reciprocal of the letter is found by finding the difference between the position of the letter and the first letter ‘A’. Then decreasing the same number of steps from the last letter ‘Z’. The character that we reach after above steps is reciprocal.
Reciprocal of Z is A and vice versa because if you reverse the position of the alphabet A will be in the position of Z.
Similarly, if the letter is a small case then the first letter will be 'a' and the last letter will be 'z'. and the definition of reciprocal remains the same.
Note: If the character is not a letter its reciprocal will be the same character.
Example 1:
Input:
S = "ab C"
Output:
zy X
Explanation:
The reciprocal of the first letter 'a' is 'z'.
The reciprocal of the second letter 'b' is 'y'.
The reciprocal of the third letter ' ' is ' '.
The reciprocal of the last letter 'C' is 'X'.
Example 2:
Input:
S = "Ish"
Output:
Rhs
Explanation:
The reciprocal of the first letter 'I' is 'R'.
The reciprocal of the second letter 's' is 'h'.
The reciprocal of the third letter 'h' is 's'.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function reciprocalString() which takes the string S as input parameter and returns the reciprocal string.
Expected Time Complexity: O(|S|) where |S| denotes the length of the string S.
Expected Auxiliary Space: O(|S|)
Constraints:
1 <= |S| <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3
class Solution:
    def reciprocalString(self, S):
        # code here

Solutions:
class Solution:

	def reciprocalString(self, S):
		s = ''
		for v in S:
			if ord('a') <= ord(v) and ord(v) <= ord('z'):
				s += chr(ord('z') - (ord(v) - ord('a')))
			elif ord('A') <= ord(v) and ord(v) <= ord('Z'):
				s += chr(ord('Z') - (ord(v) - ord('A')))
			else:
				s += v
		return s


class Solution:

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


class Solution:

	def reciprocalString(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 reciprocalString(self, S):
		m = ''
		for i in S:
			if i >= 'a' and i <= 'z':
				pos = 123 - ord(i)
				m += chr(97 + pos - 1)
			elif i >= 'A' and i <= 'Z':
				pos = 91 - ord(i)
				m += chr(65 + pos - 1)
			else:
				m += i
		return m


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		l = ['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']
		sl = list(S)
		lent = len(l) - 1
		n = ''
		for i in sl:
			if i == ' ':
				n += i
			elif str(i).islower():
				n += l[lent - l.index(i)]
			elif str(i).isupper():
				up = 0
				nl = l[lent - l.index(i.lower())]
				n += nl.upper()
		return n


class Solution:

	def reciprocalString(self, S):
		res = ''
		for e in S:
			ascii = ord(e)
			if ascii > 96 and ascii < 123:
				char_fd = ascii - 97
				char_ls = 122 - char_fd
				res = res + chr(char_ls)
			elif ascii > 64 and ascii < 91:
				char_fd = ascii - 65
				char_ls = 90 - char_fd
				res = res + chr(char_ls)
			else:
				res = res + e
		return res


class Solution:

	def reciprocalString(self, S):
		result = ''
		for char in S:
			if char.isalpha():
				if char.isupper():
					reciprocal = chr(ord('Z') - (ord(char) - ord('A')))
				else:
					reciprocal = chr(ord('z') - (ord(char) - ord('a')))
			else:
				reciprocal = char
			result += reciprocal
		return result


import string

class Solution:

	def reciprocalString(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 reciprocalString(self, S):
		st = ''
		for i in S:
			if i.isalpha():
				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
			else:
				st += i
		return st


class Solution:

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


class Solution:

	def reciprocalString(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'
		g = ''
		for i in S:
			if i.isupper():
				g += alupper[-(alupper.index(i) + 1)]
			else:
				g += allower[-(allower.index(i) + 1)]
		return g


class Solution:

	def reciprocalString(self, S):
		alphabet = []
		new = ''
		for i in range(97, 123):
			alphabet.append(chr(i))
		for i in S:
			ex = i in alphabet
			exl = i.lower() in alphabet
			if exl:
				ind = alphabet.index(i.lower())
			else:
				new += i
				continue
			if ex:
				new += alphabet[-1 - ind]
			elif exl:
				new += alphabet[-1 - ind].upper()
		return new


class Solution:

	def reciprocalString(self, S):
		d = ''
		j = 0
		for i in S:
			if i.isupper():
				d += chr(65 + 90 - ord(i))
			elif i.islower():
				d += chr(97 + 122 - ord(i))
			else:
				d += i
		return d


class Solution:

	def reciprocalString(self, S):
		outstring = []
		for i in S:
			if 'A' <= i and i <= 'Z':
				i = chr(ord('A') + ord('Z') - ord(i))
				outstring.append(i)
			elif 'a' <= i and i <= 'z':
				i = chr(ord('a') + ord('z') - ord(i))
				outstring.append(i)
			else:
				outstring.append(i)
		return ''.join(outstring)


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		opt = ''
		for ltr in range(0, len(S)):
			if ord(S[ltr]) <= 90 and ord(S[ltr]) >= 65:
				m = ord(S[ltr]) - 65
				final = 90 - m
				opt += chr(final)
			elif ord(S[ltr]) <= 122 and ord(S[ltr]) >= 97:
				n = ord(S[ltr]) - 97
				final = 122 - n
				opt += chr(final)
			elif ord(S[ltr]) == 32:
				opt += ' '
		return opt


class Solution:

	def reciprocalString(self, S):
		d = {}
		for i in range(97, 97 + 26):
			d[chr(i)] = i
		c = {}
		for i in range(65, 65 + 26):
			c[chr(i)] = i
		dk = list(d.keys())
		dk.sort()
		ck = list(c.keys())
		ck.sort()
		res = ''
		for i in S:
			if i in dk:
				x = dk.index(i) + 1
				res += dk[-x]
			if i == ' ':
				res += ' '
			elif i in ck:
				x = ck.index(i) + 1
				res += ck[-x]
		return res


class Solution:

	def reciprocalString(self, S):
		result = ''
		for i in range(len(S)):
			ch = ord(S[i])
			if ch >= 65 and ch <= 90:
				diff = ch - 65
				result += chr(90 - diff)
			elif ch >= 97 and ch <= 122:
				diff = ch - 97
				result += chr(122 - diff)
			else:
				result += S[i]
		return result


class Solution:

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


import string

class Solution:

	def reciprocalString(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].isspace():
				continue
			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 reciprocalString(self, S):
		alphabet_str = 'abcdefghijklmnopqrstuvwxyz'
		alphabet = list(alphabet_str)
		result = ''
		for i in range(len(S)):
			if S[i].islower():
				result += alphabet[-alphabet.index(S[i]) - 1]
			elif S[i].isupper():
				result += alphabet[-alphabet.index(S[i].lower()) - 1].upper()
			elif S[i] == ' ':
				result += ' '
		return result


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		dic = {'a': 'z', 'b': 'y', 'c': 'x', 'd': 'w', 'e': 'v', 'f': 'u', 'g': 't', 'h': 's', 'i': 'r', 'j': 'q', 'k': 'p', 'l': 'o', 'm': 'n', 'n': 'm', 'o': 'l', 'p': 'k', 'q': 'j', 'r': 'i', 's': 'h', 't': 'g', 'u': 'f', 'v': 'e', 'w': 'd', 'x': 'c', 'y': 'b', 'z': 'a'}
		res = ''
		for i in S:
			if i in dic:
				res += dic[i]
			elif i.isalpha() == False:
				res += i
			elif i.lower() in dic:
				res += dic[i.lower()].upper()
		return res


class Solution:

	def reciprocalString(self, S):
		res = []
		for i in range(len(S)):
			x = ord(S[i])
			if x >= 65 and x <= 90:
				x -= 65
				x = 90 - x
			elif x >= 97 and x <= 122:
				x -= 97
				x = 122 - x
			res.append(chr(x))
		S = ''
		for i in res:
			S += i
		return S


class Solution:

	def reciprocalString(self, S):
		l = len(S)
		st = ''
		for i in range(l):
			c = 0
			m = 0
			if S[i].isupper():
				c = ord(S[i]) - ord('A')
				m = ord('Z') - c
				st = st + chr(m)
			elif S[i].islower():
				c = ord(S[i]) - ord('a')
				m = ord('z') - c
				st = st + chr(m)
			else:
				st = st + S[i]
		return st


class Solution:

	def reciprocalString(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 reciprocalString(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)
			elif i == ' ':
				word[i] = ' '
		return ''.join(word)


class Solution:

	def reciprocalString(self, S):
		alp = 'abcdefghijklmnopqrstuvwxyz'
		alprev = 'zyxwvutsrqponmlkjihgfedcba'
		newst = ''
		for i in range(len(S)):
			if S[i].isupper():
				newst += alprev[alp.index(S[i].lower())].upper()
			elif S[i] == ' ':
				newst += ' '
			else:
				newst += alprev[alp.index(S[i])]
		return newst


class Solution:

	def reciprocalString(self, S):
		ans = ''
		for ch in S:
			if ch.islower():
				d = ord(ch) - 97
				ans += chr(122 - d)
			elif ch.isupper():
				d = ord(ch) - 65
				ans += chr(90 - d)
			else:
				ans += ch
		return ans


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		result = ''
		for i in S:
			if not i.isalpha():
				result += i
			elif i.isupper():
				reciprocal_code = ord('Z') - ord(i) + ord('A')
				reciprocal_char = chr(reciprocal_code)
				result += reciprocal_char
			else:
				reciprocal_code = ord('z') - ord(i) + ord('a')
				reciprocal_char = chr(reciprocal_code)
				result += reciprocal_char
		return result


class Solution:

	def reciprocalString(self, S):
		c = 'abcdefghijklmnopqrstuvwxyz'
		c1 = c[::-1]
		d = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		d1 = d[::-1]
		s = ''
		for i in range(len(S)):
			for j in range(len(c)):
				if S[i] == c[j]:
					s = s + c1[j]
					break
				if S[i] == d[j]:
					s = s + d1[j]
					break
				elif S[i] == ' ':
					s = s + ' '
					break
		return s


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		c = 'abcdefghijklmnopqrstuvwxyz'
		r = 'zyxwvutsrqponmlkjihgfedcba'
		a = ''
		s = S
		for i in s:
			k = 0
			d = ''
			if i == ' ':
				a += ' '
			elif i.isupper():
				i = i.lower()
				k = c.index(i)
				d = r[k].upper()
				a += d
			else:
				k = c.index(i)
				d = r[k]
				a += d
		return a


class Solution:

	def reciprocalString(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 i in S:
			if i.isupper() and i in alpha:
				pos = alpha.index(i)
				output += rev_alpha[pos]
			elif i.islower() and i.upper() in alpha:
				pos = alpha.index(i.upper())
				output += rev_alpha[pos].lower()
			else:
				output += i
		return output


class Solution:

	def reciprocalString(self, S):
		output = ''
		for item in S:
			if not item.isalpha():
				output += item
			elif item.islower():
				output += chr(219 - ord(item))
			else:
				output += chr(155 - ord(item))
		return output


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		n = len(S)
		ans = ''
		for i in range(n):
			num = ord(S[i])
			if 65 <= num <= 90:
				diff = num - 65
				get = 90 - diff
				char = chr(get)
				ans += char
			elif 97 <= num <= 122:
				diff = num - 97
				get = 122 - diff
				char = chr(get)
				ans += char
			else:
				ans += S[i]
		return ans


class Solution:

	def reciprocalString(self, S):
		s = 'abcdefghijklmnopqrstuvwxyz'
		u = s.upper()
		p = ''
		for index in range(len(S)):
			if S[index] in s:
				p += s[25 - s.index(S[index])]
			elif S[index] in u:
				p += u[25 - u.index(S[index])]
			else:
				p += S[index]
		return p


class Solution:

	def reciprocalString(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()
			else:
				st += S[i]
		return st


class Solution:

	def reciprocalString(self, S):
		alphabets_list = list('abcdefghijklmnopqrstuvwxyz')
		capital_list = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
		result = ''
		for i in range(len(S)):
			if S[i] == ' ':
				result += ' '
			if S[i].islower():
				index = alphabets_list.index(S[i])
				result += alphabets_list[-index - 1]
			elif S[i].isupper():
				index = capital_list.index(S[i])
				result += capital_list[-index - 1]
		return result


class Solution:

	def reciprocalString(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


class Solution:

	def reciprocalString(self, S):
		l = ''
		for i in S:
			m = ord(i)
			if (m < 91) & (m > 64):
				l += chr(155 - m)
			elif (m < 123) & (m > 96):
				l += chr(219 - m)
			else:
				l += i
		return l


class Solution:

	def reciprocalString(self, S):
		ref = 'abcdefghijklm nopqrstuvwxyz'
		em = ''
		for i in range(len(S)):
			for j in range(len(ref)):
				if S[i] == ref[j] or S[i] == ref[j].upper():
					if S[i].isupper():
						em += ref[-(j + 1)].upper()
					else:
						em += ref[-(j + 1)]
		return em


class Solution:

	def reciprocalString(self, S):
		out = ''
		for i in S:
			if i == ' ':
				out += i
			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 reciprocalString(self, S):
		res = ''
		upLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		downLetters = upLetters.lower()
		for letter in S:
			if letter.isupper():
				res += upLetters[-upLetters.index(letter) - 1]
			elif letter.islower():
				res += downLetters[-downLetters.index(letter) - 1]
			else:
				res += letter
		return res


class Solution:

	def reciprocalString(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', ' ': '53'}
		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 reciprocalString(self, S):
		b = ''
		for i in S:
			a = ord(i)
			if a < 123 and a > 96:
				b = b + chr(122 + (97 - a))
			elif a < 91 and a > 64:
				b = b + chr(90 + (65 - a))
			else:
				b = b + i
		return b


class Solution:

	def reciprocalString(self, S):
		n = ''
		for i in S:
			if ord(i) >= 97 and ord(i) <= 122:
				value = ord(i) - 97
				temp = 122 - value
				n += chr(temp)
			elif ord(i) >= 65 and ord(i) <= 90:
				value = ord(i) - 65
				temp = 90 - value
				n += chr(temp)
			else:
				n += i
		return n


import string

class Solution:

	def reciprocalString(self, S):
		uppercase = string.ascii_uppercase
		lowercase = string.ascii_lowercase
		upperrev = uppercase[::-1]
		lowerrev = lowercase[::-1]
		out = ''
		for i in S:
			if i in lowercase:
				out += lowerrev[lowercase.index(i)]
			elif i in uppercase:
				out += upperrev[uppercase.index(i)]
			else:
				out += i
		return out


class Solution:

	def reciprocalString(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')))
			elif ord(char) >= ord('A') and ord(char) <= ord('Z'):
				res += chr(ord('Z') - (ord(char) - ord('A')))
			else:
				res += char
		return res


class Solution:

	def reciprocalString(self, S):
		str = ''
		for i in S:
			if i.isupper():
				str += chr(ord('A') + ord('Z') - ord(i))
			elif i.islower():
				str += chr(ord('a') + ord('z') - ord(i))
			elif i.isspace():
				str += ' '
		return str


class Solution:

	def reciprocalString(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 reciprocalString(self, S):
		alphabets = 'abcdefghijklmnopqrstuvwxyz'
		alphabets_list = list(alphabets)
		capital = alphabets.upper()
		capital_list = list(capital)
		result = ''
		for index in range(len(S)):
			if S[index].isalpha() and S[index].islower():
				char_postition_alpha = alphabets_list.index(S[index])
				result += alphabets[-char_postition_alpha - 1]
			elif S[index].isalpha() and S[index].isupper():
				char_postition_alpha = capital_list.index(S[index])
				result += capital[-char_postition_alpha - 1]
			else:
				result += S[index]
		return result


class Solution:

	def reciprocalString(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
			elif i.isupper():
				v += ord(i) - 64
				v = 26 - v
				ll += chr(v + 65)
				v = 0
			else:
				ll += i
		return ll


class Solution:

	def reciprocalString(self, S):
		lis = list(S)
		l_fin = []
		for i in lis:
			if 65 <= ord(i) <= 90:
				rev = ord(i) - 65
				l_fin.append(chr(90 - rev))
			elif 97 <= ord(i) <= 122:
				rev = ord(i) - 97
				l_fin.append(chr(122 - rev))
			else:
				l_fin.append(i)
		return ''.join(l_fin)


class Solution:

	def reciprocalString(self, S):
		s = ''
		for i in S:
			if ord(i) >= 97 and ord(i) <= 122:
				c = ord(i) - 97
				d = 122 - c
				s += chr(d)
			elif ord(i) >= 65 and ord(i) <= 90:
				c = ord(i) - 65
				d = 90 - c
				s += chr(d)
			else:
				s += i
		return s


class Solution:

	def reciprocalString(self, S):
		f = ''
		for i in S:
			if ord(i) > 64 and ord(i) < 92:
				z = ord(i) - 64
				l = 91 - z
				f += chr(l)
			elif ord(i) > 96 and ord(i) < 123:
				z = ord(i) - 96
				l = 123 - z
				f += chr(l)
			else:
				f += i
		return f


class Solution:

	def reciprocalString(self, S):
		dic = {chr(i): chr(122 - i + 97) for i in range(97, 123)}
		res = ''
		for elm in S:
			if elm.isupper():
				elm = elm.lower()
				res += dic[elm].upper()
			elif elm.islower():
				res += dic[elm]
			else:
				res += elm
		return res


class Solution:

	def reciprocalString(self, S):
		ans = ''
		for i in S:
			if i.isalpha():
				if i.islower():
					ans += chr(122 - (ord(i) - 97))
				else:
					ans += chr(90 - (ord(i) - 65))
			else:
				ans += i
		return ans


class Solution:

	def reciprocalString(self, S):
		lower_alpha = 'abcdefghijklmnopqrstuvwxyz'
		upper_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		new_str = ''
		for char in S:
			if char.isalpha():
				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]
			else:
				new_str += char
		return new_str


class Solution:

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


class Solution:

	def reciprocalString(self, S):
		ans = []
		for c in S:
			if c.islower():
				ans.append(chr(ord('z') - ord(c) + ord('a')))
			elif c.isupper():
				ans.append(chr(ord('Z') - ord(c) + ord('A')))
			else:
				ans.append(c)
		return ''.join(ans)


import string

class Solution:

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


class Solution:

	def reciprocalString(self, s):
		l = 'abcdefghijklmnopqrstuvwxyz'
		u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		res = ''
		for i in s:
			if i.isupper():
				a = u.index(i)
				res = res + u[-(a + 1)]
			elif i.islower():
				b = l.index(i)
				res = res + l[-(b + 1)]
			elif i.isspace():
				res += i
		return res


class Solution:

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


class Solution:

	def reciprocalString(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 reciprocalString(self, S):
		capital = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		small = 'abcdefghijklmnopqrstuvwxyz'
		string = ''
		for i in S:
			if i.isalpha():
				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