Given a string str of lowercase alphabets only. The task is to replace every character by some new character. The new character belongs to (small case only) Replacement of str[i] is determined by:
str[i] = Character obtained after traversing ascii(str[i]) no. of characters in ‘a-z’ repeatedly after str[i].
Input: str = “geeksforgeeks”
In the above case str = “geeksforgeeks”,
the ASCII value of ‘g’ is 103 therefore ‘g’ has been replaced by moving 103 times from ‘g’ in the desired range i.e., a-z.
Hence, character ‘g’ is replaced by ‘f’.
Similarly, the complete string “geeksforgeeks” becomes “fbbnddvbfbbnd”.
Input: str = “science”
- Traverse the string.
- For every i, find the character that needs to be replaced with str[i].
- Replace str[i] with that character.
Below is the implementation of above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Replace every character of string by character whose ASCII value is K times more than it
- Replace all occurrences of character X with character Y in given string
- Program to replace every space in a string with hyphen
- Replace every consonant sequence with its length in the given string
- Replace every vowels with lexicographically next vowel in a String
- Find a string such that every character is lexicographically greater than its immediate next character
- Map every character of one string to another such that all occurrences are mapped to the same character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Replace a character c1 with c2 and c2 with c1 in a string S
- Minimum string such that every adjacent character of given string is still adjacent
- Shortest distance to every other character from given character
- Check if both halves of the string have at least one different character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Longest subsequence with at least one character appearing in every string
- Reverse every word of the string except the first and the last character
- String formed with middle character of every right substring followed by left sequentially
- Maximum repeating character for every index in given String
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Replace all occurrences of string AB with C without using extra space
- Replace two substrings (of a string) with each other
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.