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
- 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
- InfyTQ 2019 : Find the position from where the parenthesis is not balanced
- Introduction to Data Structures | 10 most commonly used Data Structures
- Implementing Forward Iterator in BST
- Nodes from given two BSTs with sum equal to X
- Triplet with a given sum in BST | Set 2
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.