text: Number of ways to make binary string of length N such that 0 s always occur together in groups of size K | Javascript implementation of the approach ; Function to return no of ways to build a binary string of length N such that 0 s always occur in groups of size K ; Driver Code
code: let mod = 1000000007 ; function noOfBinaryStrings ( N , k ) { let dp = new Array ( 100002 ) ; for ( let i = 1 ; i <= k - 1 ; i ++ ) { dp [ i ] = 1 ; } dp [ k ] = 2 ; for ( let i = k + 1 ; i <= N ; i ++ ) { dp [ i ] = ( dp [ i - 1 ] + dp [ i - k ] ) % mod ; } return dp [ N ] ; } let N = 4 ; let K = 2 ; document . write ( noOfBinaryStrings ( N , K ) ) ;