Given an integer N which shows the size of the string and in the next line given a string which contains a string of character with only zero and one. The task is to remove a single character each time that comes in between the two zero characters.
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 patterns again.
Time Complexity : O(N), where N is the size of input string.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Modify string by removing vowels in between two consonants
- Remove Trailing Zeros From string in C++
- Remove Leading Zeros From String in Java
- Maximum difference of zeros and ones in binary string
- Python | Remove leading zeros from an IP address
- Maximum difference of zeros and ones in binary string | Set 2 (O(n) time)
- Count binary strings with twice zeros in first half
- Remove leading zeros from a Number given as a string
- Maximum number of strings that can be formed with given zeros and ones
- Count ways to split a Binary String into three substrings having equal count of zeros
- Build Lowest Number by Removing n digits from a given number
- Removing spaces from a string using Stringstream
- Find longest palindrome formed by removing or shuffling chars from string
- Character replacement after removing duplicates from a string
- Removing punctuations from a given string
- Minimum sum of squares of character counts in a given string after removing k characters
- Ways of transforming one string to other by removing 0 or more characters
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Subsequence queries after removing substrings
- Removing row or column wise duplicates from matrix of characters
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.