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
- Design a stack which can give maximum frequency element
- Reverse the Sentence using Stack
- Analyzing BufferOverflow with GDB
- Check if the two given stacks are same
- Iterative Postorder traversal | Set 3
- Sliding Window Maximum (Maximum of all subarrays of size k) using stack in O(n) time
- Move all zeros to start and ones to end in an Array of random integers
- Find maximum in stack in O(1) without using additional stack
- Replace array elements by sum of next two consecutive elements
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.