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
def check ( s ) : NEW_LINE INDENT n = len ( s ) ; NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( s [ i ] == '1' and s [ i - 1 ] == '1' and s [ i - 2 ] == '1' ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT DEDENT DEDENT def countStr ( i , s ) : NEW_LINE INDENT if ( i < 0 ) : NEW_LINE INDENT if ( check ( s ) ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return 0 ; NEW_LINE DEDENT s [ i ] = '0' ; NEW_LINE ans = countStr ( i - 1 , s ) ; NEW_LINE s [ i ] = '1' ; NEW_LINE ans += countStr ( i - 1 , s ) ; NEW_LINE s [ i ] = '0' ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 ; NEW_LINE s = list ( '0' * N ) ; NEW_LINE print ( countStr ( N - 1 , s ) ) ; NEW_LINE DEDENT