Minimum steps to remove substring 010 from a binary string | Function to find the minimum steps ; substring "010" found ; Get the binary string ; Find the minimum steps
function minSteps ( str ) { let count = 0 ; for ( let i = 0 ; i < str . length - 2 ; i ++ ) { if ( ( str [ i ] ) == ' ' ) { if ( str [ i + 1 ] == ' ' ) { if ( str [ i + 2 ] == ' ' ) { count ++ ; i += 2 ; } } } } return count ; } let str = " " ; document . write ( minSteps ( str ) ) ;