Given an integer N which shows the size of the string and in the next line given a string which contain string of character with only zero and one. Task is to remove single character each time which comes in between the two zero character.
During each turn, only one character from the string will be removed that satisfies the following condition :
- It must be surrounded by zeroes on both sides.
Input : str = "1001 Output : str = "1001" Input : str = "10101 Output : str = "1001"
Use a loop from 1 to N – 1 and check if any element lies between two zeros such that s[i – 1] = ‘0’ and s[i + 1] = ‘0’. If the condition is satisfied then, delete the character at that position, ad start searching for pattern again.
Time Complexity : O(N), where N is the size of input string.
- Remove Trailing Zeros From string in C++
- Remove Leading Zeros From String in Java
- Python | Remove leading zeros from an IP address
- Count binary strings with twice zeros in first half
- Maximum difference of zeros and ones in binary string
- Maximum difference of zeros and ones in binary string | Set 2 (O(n) time)
- Removing punctuations from a given string
- Java | Removing whitespaces using Regex
- Removing spaces from a string using Stringstream
- Subsequence queries after removing substrings
- Print reverse string after removing vowels
- Modify string by removing vowels in between two consonants
- Ways of transforming one string to other by removing 0 or more characters
- Balance a string after removing extra brackets
- Character replacement after removing duplicates from a string
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.
Improved By : manishshaw1