Count the number of ways to traverse a Matrix | Find factorial ; Find number of ways to reach mat [ m - 1 ] [ n - 1 ] from mat [ 0 ] [ 0 ] in a matrix mat [ ] [ ] ] ; Driver code ; Function call
def factorial ( n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT res *= i NEW_LINE DEDENT return res NEW_LINE DEDENT def countWays ( m , n ) : NEW_LINE INDENT m = m - 1 NEW_LINE n = n - 1 NEW_LINE return ( factorial ( m + n ) // ( factorial ( m ) * factorial ( n ) ) ) NEW_LINE DEDENT m = 5 NEW_LINE n = 5 NEW_LINE result = countWays ( m , n ) NEW_LINE print ( result ) NEW_LINE