VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-print-reciprocal-letters/

⇱ Program to print reciprocal of letters - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print reciprocal of letters

Last Updated : 11 Jul, 2025

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 :    KIZPSZI

Input  :    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:


Output
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)

Comment
Article Tags:
Article Tags: