Given a string str, the task is to replace all occurrences of the given X with given Y and also remove any occurrances of the given Z if present in it with no extra space
Input: str = “batman”, X = ‘a’, Y = ‘d’, Z = ‘b’
Input: str = “abba”, X = ‘a’, Y = ‘d’, Z = ‘b’
- The idea is based on the 2 pointers.
- Let two-variable start and end points to the beginning and end of the string.
- Now if the character at the start is Z, replace it with a character not having Y at another pointer pointing to a location > start keeping in mind to replace character X with Y if found.
Below is the implementation of the above approach:
- Find longest palindrome formed by removing or shuffling chars from string
- Check if a string can be converted to another string by replacing vowels and consonants
- Count of integers obtained by replacing ? in the given string that give remainder 5 when divided by 13
- Removing punctuations from a given string
- Removing spaces from a string using Stringstream
- Modify string by removing vowels in between two consonants
- Ways of transforming one string to other by removing 0 or more characters
- Balance a string after removing extra brackets
- Print reverse string after removing vowels
- Character replacement after removing duplicates from a string
- Minimize the length of string by removing occurrence of only one character
- Reduce the string by removing K consecutive identical characters
- Lexicographically smallest string formed by removing at most one character
- Minimum sum of squares of character counts in a given string after removing k characters
- Check if string remains palindrome after removing given number of characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.