![]() |
VOOZH | about |
Given a string s consisting only of English alphabets, transform each character by replacing it with the character present at the corresponding position in the reversed English alphabet. Thus, 'a' becomes 'z', 'b' becomes 'y', 'c' becomes 'x', and similarly 'z' becomes 'a'. Uppercase letters are also transformed in the same way while preserving their case. Return the resulting transformed string.
Examples:
Input: s = "Hello"
Output: Svool
Explanation: 'H' is replaced by 'S', 'e' by 'v', 'l' by 'o', and 'o' by 'l'. Therefore, the transformed string becomes "Svool".
Input: s = "GfG"
Output: TuT
Explanation: 'G' is replaced by 'T' and 'f' is replaced by 'u'. Hence, the resulting string is "TuT".
Table of Content
The idea is to traverse the string and generate a new transformed string by replacing each character with its corresponding character in the reversed English alphabet. Finally, return the newly formed string.
TuT
Time Complexity: O(n)
Auxiliary Space: O(n)
The idea is to traverse the string and directly replace each character with its corresponding character in the reversed English alphabet. Since the transformation is performed in-place, no extra space is required.
TuT
Time Complexity: O(n)
Auxiliary Space: O(1)