x 62. Unique Paths
Recursive
const memo = {};
const uniquePaths = function(m, n) {
const key = m + ',' + n;
if (key in memo) return memo[key];
if (m === 1 || n === 1) return 1
if (m === 0 || n === 0) return 0;
memo[key] = uniquePaths(m-1, n) + uniquePaths(m, n-1);
return memo[key];
};2nd try
time: O(m x n)
space: O(m or n)
1st try
time: O(m x n)
space: O(m x n)
Last updated