![]() |
VOOZH | about |
Given string str of size N consisting of lowercase English alphabets, the task is to encode the given string as follows:
Examples:
Input: str = "geeksforgeeks"
Output: "miiukkcimiiuk"
Explanation:
g changed to m (distance between g & a is 6, distance between m & g is 6)
e changed to i (distance between e & a is 4, distance between i & e is 4)
and same for other characters as well.Input: str = "cycleofalphabet"
Output: "ewewickaweoacim"
Approach: This problem can be solved using the following steps:
Below is the implementation of the above approach:
ewewickaweoacim
Time Complexity: O(N)
Auxiliary Space: O(1)