Count of binary strings of length N having equal count of 0 ' s ▁ and ▁ 1' s | Javascript program for the above approach ; Function to calculate C ( n , r ) % MOD DP based approach ; Corner case ; Stores the last row of Pascal 's Triangle ; Initialize top row of pascal triangle ; Construct Pascal 's Triangle  from top to bottom ; Fill current row with the help of previous row ; C ( n , j ) = C ( n - 1 , j ) + C ( n - 1 , j - 1 ) ; Driver Code
var MOD = 1000000007 ; function nCrModp ( n , r ) { if ( n % 2 == 1 ) { return - 1 ; } var C = Array ( r + 1 ) . fill ( 0 ) ; C [ 0 ] = 1 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = Math . min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % MOD ; } return C [ r ] ; } var N = 6 ; document . write ( nCrModp ( N , N / 2 ) ) ;