text: Count of Binary Strings of length N such that frequency of 1 ' s ▁ exceeds ▁ frequency ▁ of ▁ 0' s | Java program to implement the above approach ; 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
code: import java . util . * ; class GFG { static int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static int countOfString ( int N ) { int Stotal = ( int ) Math . pow ( 2 , N ) ; int Sequal = 0 ; if ( N % 2 == 0 ) Sequal = binomialCoeff ( N , N / 2 ) ; int S1 = ( Stotal - Sequal ) / 2 ; return S1 ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . print ( countOfString ( N ) ) ; } }