Count of Binary Strings of length N such that frequency of 1 ' s ▁ exceeds ▁ frequency ▁ of ▁ 0' s | Function to calculate and return the value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate the value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; Function to return the count of binary Strings of length N such that frequency of 1 ' s ▁ exceed ▁ that ▁ of ▁ 0' s ; Count of N - length binary Strings ; Count of N - length binary Strings having equal count of 0 ' s ▁ and ▁ 1' s ; For even length Strings ; Driver Code
function binomialCoeff ( n , k ) { let res = 1 ; if ( k > n - k ) k = n - k ; for ( let i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function countOfString ( N ) { let Stotal = Math . pow ( 2 , N ) ; let Sequal = 0 ; if ( N % 2 == 0 ) Sequal = binomialCoeff ( N , N / 2 ) ; let S1 = ( Stotal - Sequal ) / 2 ; return S1 ; } let N = 3 ; document . write ( countOfString ( N ) ) ;