Count non decreasing subarrays of size N from N Natural numbers | Returns value of Binomial Coefficient C ( n , k ) ; Since nC0 is 1 ; Compute next row of pascal triangle using the previous row ; Function to find the count of required subarrays ; The required count is the binomial coefficient as explained in the approach above ; Driver Function
def binomialCoeff ( n , k ) : NEW_LINE INDENT C = [ 0 ] * ( k + 1 ) ; NEW_LINE C [ 0 ] = 1 ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , k ) , 0 , - 1 ) : NEW_LINE INDENT C [ j ] = C [ j ] + C [ j - 1 ] ; NEW_LINE DEDENT DEDENT return C [ k ] ; NEW_LINE DEDENT def count_of_subarrays ( N ) : NEW_LINE INDENT count = binomialCoeff ( 2 * N - 1 , N ) ; NEW_LINE return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 3 ; NEW_LINE print ( count_of_subarrays ( N ) ) ; NEW_LINE DEDENT