Given a string s, our task is to move all the occurrence of letter x to the end of the string s using recursion.
Note: If there are only letter x in the given string then return the string unaltered.
Input: s= “geekxsforgexxeksxx”
All occurrence of letter ‘x’ is moved to the end.
Input: s = “xxxxx”
Since there are only letter x in the given string therefore the output is unaltered.
To solve the problem mentioned above we can use Recursion. Traverse in the string and check recursively if the current character is equal to the character ‘x’ or not. If not then print the character otherwise move to the next character until the length of the string s is reached.
Below is the implementation of the 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
- String containing first letter of every word in a given string with spaces
- Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word
- Get the first letter of each word in a string using regex in Java
- First uppercase letter in a string (Iterative and Recursive)
- Check if the string contains consecutive letters and each letter occurs exactly once
- Program to accept String starting with Capital letter
- Get K-th letter of the decoded string formed by repeating substrings
- Number of positions where a letter can be inserted such that a string becomes palindrome
- Move all special char to the end of the String
- Move spaces to front of string in single traversal
- Python code to move spaces to front of string in single traversal
- Convert a String to an Integer using Recursion
- Program for length of a string using recursion
- Print reverse of a string using recursion
- Length of longest palindromic sub-string : Recursion
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.