Find the number of binary strings of length N with at least 3 consecutive 1 s | Function that returns true if s contains three consecutive 1 's ; Function to return the count of required strings ; Driver code
function check ( s ) { let n = s . length ; for ( let i = 2 ; i < n ; i ++ ) { if ( s [ i ] == ' ' && s [ i - 1 ] == ' ' && s [ i - 2 ] == ' ' ) return true ; } return false ; } function countStr ( i , s ) { if ( i < 0 ) { if ( check ( s ) ) return 1 ; return 0 ; } let myNameChars = s . split ( " " ) ; myNameChars [ i ] = ' ' ; s = ( myNameChars ) . join ( " " ) ; let ans = countStr ( i - 1 , s ) ; let myChar = s . split ( " " ) ; myChar [ i ] = ' ' ; s = ( myChar ) . join ( " " ) ; ans += countStr ( i - 1 , s ) ; let myChar1 = s . split ( " " ) ; myChar1 [ i ] = ' ' ; s = ( myChar1 ) . join ( " " ) ; return ans ; } let N = 4 ; let s = " " ; document . write ( countStr ( N - 1 , s ) ) ;