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++
- Python | Remove leading zeros from an IP address
- Maximum difference of zeros and ones in binary string
- Remove Leading Zeros From String in Java
- Count binary strings with twice zeros in first half
- Maximum difference of zeros and ones in binary string | Set 2 (O(n) time)
- Removing punctuations from a given string
- Removing spaces from a string using Stringstream
- Java | Removing whitespaces using Regex
- Subsequence queries after removing substrings
- Print reverse string after removing vowels
- Character replacement after removing duplicates from a string
- Ways of transforming one string to other by removing 0 or more characters
- Modify string by removing vowels in between two consonants
- Balance a string after removing extra brackets
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