Given m x n matrix, count of all unique possible paths from top left to the bottom right. From each cell, only move right or down is allowed.
The algorithm determines the number of paths by starting at the destination and working backwards towards the source. At each step, the count is calculated by considering the possible paths from the current position: moving up and moving right.
def count(m, n): if m == 1 or n == 1: return 1 return count(m - 1, n) + count(m, n - 1) m = 2 n = 2 print(count(m, n))
function count(m, n) { if (m == 1 || n == 1) { return 1; } return count(m - 1, n) + count(m, n - 1); } const m = 2; const n = 2; console.log(count(m, n));