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:
- Minimum steps to delete a string by deleting substring comprising of same characters
- Minimum steps to convert one binary string to other only using negation
- Minimum splits in a binary string such that every substring is a power of 4 or 6.
- Minimum characters to be replaced to remove the given substring
- Minimum changes required to make first string substring of second string
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Ways to remove one element from a binary string so that XOR becomes zero
- 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 swaps required to convert one binary string to another
- Minimum number of operations required to sum to binary string S
- Minimum swaps required to make a binary string alternating
- Minimum number of replacements to make the binary string alternating | Set 2
- Minimum number of operations on a binary string such that it gives 10^A as remainder when divided by 10^B
- Minimum number of palindromic subsequences to be removed to empty a binary 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 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.