Number of arrays of size N whose elements are positive integers and sum is K | Return nCr ; C [ 0 ] = 1 ; nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Return the number of array that can be formed of size n and sum equals to k . ; Driver Code
function binomialCoeff ( n , k ) { var C = Array ( k + 1 ) . fill ( 0 ) ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = Math . min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } function countArray ( N , K ) { return binomialCoeff ( K - 1 , N - 1 ) ; } var N = 2 , K = 3 ; document . write ( countArray ( N , K ) ) ;