Minimum steps to remove substring 010 from a binary string | CPP program to calculate steps to remove substring 010 from a binary string ; Function to find the minimum steps ; substring "010" found ; Driver code ; Get the binary string ; Find the minimum steps
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minSteps ( string str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) - 2 ; i ++ ) { if ( str [ i ] == '0' ) { if ( str [ i + 1 ] == '1' ) { if ( str [ i + 2 ] == '0' ) { count ++ ; i += 2 ; } } } } return count ; } int main ( ) { string str = "0101010" ; cout << minSteps ( str ) ; return 0 ; }