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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Replace every character of string by character whose ASCII value is K times more than it
- Replace a character c1 with c2 and c2 with c1 in a string S
- Find a string such that every character is lexicographically greater than its immediate next character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Map every character of one string to another such that all occurrences are mapped to the same character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Count substrings that starts with character X and ends with character Y
- Longest Common Prefix using Character by Character Matching
- Shortest distance to every other character from given character
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Find the character in first string that is present at minimum index in second string
- Queries to find the last non-repeating character in the sub-string of a given string
- Queries to find the first non-repeating character in the sub-string of a string
- Convert the string into palindrome string by changing only one character.