![]() |
VOOZH | about |
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 first letter 'A'. Then moving the same number of steps from 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, T is the reciprocal of G, J is the reciprocal of Q.
Examples :
Input : PRAKHAR
Output : KIZPSZIInput : VARUN
Output : EZIFM
Just use a mathematical formula which gives the reciprocal of each character
Reciprocal(x) = ASCII('Z') - ASCII(x) + ASCII('A')
The ASCII value of Z and A will change according
to the uppercase and lowercase.
Implementation:
The reciprocal of Geeks for Geeks is - Tvvph uli Tvvph
Time Complexity: O(n), where n is the length of the string.
Auxiliary Space: O(1)