Check if a string has m consecutive 1 ' s ▁ or ▁ 0' s | Function that checks if the binary string contains m consecutive 1 ' s ▁ or ▁ 0' s ; length of binary string ; counts zeros ; counts 1 's ; count consecutive 0 's ; count consecutive 1 's ; Driver Code ; function call
< ? php function check ( $ s , $ m ) { $ l = count ( $ s ) ; $ c1 = 0 ; $ c2 = 0 ; for ( $ i = 0 ; $ i <= $ l ; $ i ++ ) { if ( $ s [ $ i ] == '0' ) { $ c2 = 0 ; $ c1 ++ ; } else { $ c1 = 0 ; $ c2 ++ ; } if ( $ c1 == $ m or $ c2 == $ m ) return true ; } return false ; } $ s = "001001" ; $ m = 2 ; if ( check ( $ s , $ m ) ) echo " YES " ; else echo " NO " ; ? >