Number of M | Function to find the number of M - length sorted arrays possible using numbers from the range [ 1 , N ] ; If size becomes equal to m , that means an array is found ; Include current element , increase size by 1 and remain on the same element as it can be included again ; Exclude current element ; Return the sum obtained in both the cases ; Driver Code ; Given Input ; Function Call
def countSortedArrays ( start , m , size , n ) : NEW_LINE INDENT if ( size == m ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( start > n ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT notTaken , taken = 0 , 0 NEW_LINE taken = countSortedArrays ( start , m , size + 1 , n ) NEW_LINE notTaken = countSortedArrays ( start + 1 , m , size , n ) NEW_LINE return taken + notTaken NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n , m = 2 , 3 NEW_LINE print ( countSortedArrays ( 1 , m , 0 , n ) ) NEW_LINE DEDENT