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:
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.
- Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word
- Move all special char to the end of the String
- Minimum move to end operations to make all strings equal
- String containing first letter of every word in a given string with spaces
- Get the first letter of each word in a string using regex in Java
- Minimum letters to be removed to make all occurrences of a given letter continuous
- Check if the string contains consecutive letters and each letter occurs exactly once
- Number of positions where a letter can be inserted such that a string becomes palindrome
- First uppercase letter in a string (Iterative and Recursive)
- Get K-th letter of the decoded string formed by repeating substrings
- Program to accept String starting with Capital letter
- Minimum number of operations to move all uppercase characters before all lower case characters
- Find letter's position in Alphabet using Bit operation
- Minimum swaps required to move all vowels occurs after consonants in a given string
- Generating all possible Subsequences using Recursion
- Program to find all Factors of a Number using recursion
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Print reverse of a string using recursion
- Program for length of a string using recursion
- Convert a String to an Integer using Recursion