Given a string str, the task is to remove all the continuous occurrences of a and all occurrences of b and print the resultant string.
Input: str = “abcddabcddddabbbaaaaaa”
‘abcddabcddddabbbaaaaaa’ will not result in ‘acddacddddaa’ because after removing the required occurrences, the string will become ‘acddacddddaa’ which will result in ‘acddacdddda’
Input: str = “aacbccdbsssaba”
Approach: We initialize an empty result string. We traverse the input string if the current character is b or current character is a and last character of result string is also a then ignore the character else push the character into the result string.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Pattern Occurrences : Stack Implementation Java
- Maximum number of continuous Automorphic numbers
- Remove repeated digits in a given number
- Remove brackets from an algebraic string containing + and - operators
- Number of ways to remove a sub-string from S such that all remaining characters are same
- Check given string is oddly palindrome or not | Set 2
- Level order traversal in spiral form using stack and multimap
- Find the missing end tag in the given HTML Code
- Unique subsequences of length K with given sum
- Check if a string can be split into even length palindromic substrings
- Find index after traversing a permutation Array of 1 to N by K steps
- Maximize removal of adjacent array elements based on their absolute value
- Sum of decomposition values of all suffixes of an Array
- Real-time application of Data Structures
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.