Count sequences of given length having non | Function to find the Binomial Coefficient C ( n , r ) ; Stores the value C ( n , r ) ; Update C ( n , r ) = C ( n , n - r ) ; Find C ( n , r ) iteratively ; Return the final value ; Function to find number of sequence whose prefix sum at each index is always non - negative ; Find n ; Value of C ( 2 n , n ) ; Catalan number ; Prlet the answer ; Given M and X ; Function Call
function binCoff ( n , r ) { let val = 1 ; let i ; if ( r > ( n - r ) ) r = ( n - r ) ; for ( i = 0 ; i < r ; i ++ ) { val *= ( n - i ) ; val /= ( i + 1 ) ; } return val ; } function findWays ( M ) { let n = M / 2 ; let a , b , ans ; a = binCoff ( 2 * n , n ) ; b = a / ( n + 1 ) ; document . write ( b ) ; } let M = 4 , X = 5 ; findWays ( M ) ;