Given a binary string, the task is to count the minimum steps to remove substring “010” from this binary string.
Input: binary_string = “0101010”
Switching 0 to 1 at index 2 and index 4 will remove the substring 010.
Hence the number of steps needed is 2.
Input: binary_string = “010”
Switching any one 0 to 1 or 1 to 0 will remove the substring 010.
Hence the number of steps needed is 1.
- Iterate the string from beginning to end-2 of the binary string.
- If in binary string continuously three characters are ‘0’, ‘1’, ‘0’ then any one character can be change so that one step will be count.
- Increase the loop counter by 2.
Below is the implementation of the above approach:
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.
- Count of non-overlapping sub-strings "101" and "010" in the given binary string
- Minimum number of steps needed to remove the substring K from given string
- Minimum steps to delete a string by deleting substring comprising of same characters
- Minimum length of substring whose rotation generates a palindromic substring
- Minimum steps to convert one binary string to other only using negation
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Minimum characters to be replaced to remove the given substring
- Minimum splits in a binary string such that every substring is a power of 4 or 6.
- Minimum flips required in a binary string such that all K-size substring contains 1
- Minimum substring flips required to convert given binary string to another
- Minimum changes required to make first string substring of second string
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Minimum non-adjacent pair flips required to remove all 0s from a Binary String
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Find minimum number of steps to reach the end of String
- Count substring of Binary string such that each character belongs to a palindrome of size greater than 1
- Maximize count of 0s in left and 1s in right substring by splitting given Binary string
- Maximum splits in binary string such that each substring is divisible by given odd number
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.