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:
- 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
- Reduce the string to minimum length with the given operation
- Sort the given stack elements based on their modulo with K
- Check if the bracket sequence can be balanced with at most one change in the position of a bracket | Set 2
- Check if any K ranges overlap at any point
- Stack in Python
- Find the winner of the Game to Win by erasing any two consecutive similar alphabets
- Convert ternary expression to Binary Tree using Stack
- Find all unique pairs of maximum and second maximum elements over all sub-arrays in O(NlogN)
- Python | Stack using Doubly Linked List
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.