Count N | Function to count binary strings of length N having substring "11" ; Initialize dp of size N + 1 ; Base Cases ; Stores the first N powers of 2 ; Generate ; Iterate over the range [ 2 , N ] ; Print total count of substrings ; Driver Code
function binaryStrings ( N ) { var dp = Array ( N + 1 ) . fill ( 0 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; var power = Array ( N + 1 ) . fill ( 0 ) ; power [ 0 ] = 1 ; for ( i = 1 ; i <= N ; i ++ ) { power [ i ] = 2 * power [ i - 1 ] ; } for ( i = 2 ; i <= N ; i ++ ) { dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + power [ i - 2 ] ; } document . write ( dp [ N ] ) ; } var N = 12 ; binaryStrings ( N ) ;