Number of ways to reach ( M , N ) in a matrix starting from the origin without visiting ( X , Y ) | Function for computing nCr ; Function to find factorial of a number ; Function for counting the number of ways to reach ( m , n ) without visiting ( x , y ) ; Given Dimensions of Matrix ; Cell not to be visited ; Function Call
function nCr ( n , r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } function fact ( n ) { let res = 1 ; for ( let i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } function countWays ( m , n , x , y ) { return nCr ( m + n , m ) - nCr ( x + y , x ) * nCr ( m + n - x - y , m - x ) ; } let m = 5 ; let n = 4 ; let x = 3 ; let y = 2 ; document . write ( countWays ( m , n , x , y ) ) ;